Creating a random dot pattern with increasing grayscale
17 views (last 30 days)
Show older comments
Ahmed Othman
on 17 Aug 2022
Answered: Image Analyst
on 17 Aug 2022
Hi,
I am trying to numerically generate a dotted pattern made of dot of 2 pixels which are randomly distributed and save it as an image. I have tried
sz = 500;
Ah = rand(sz,sz);
imshow(Ah);
but I cannot control the size of the dots.
0 Comments
Accepted Answer
Image Analyst
on 17 Aug 2022
Try this. Adapt parameters as needed.
% Define output image.
imageRows = 48;
imageColumns = 64;
grayImage = zeros(imageRows, imageColumns, 'uint8');
% Define dot parameters.
dotRows = 1;
dotColumns = 2;
maxDotBrightness = 255;
minDotBrightness = 120;
numDotsToBePlaced = 100;
numDotsPlacedSoFar = 0;
while numDotsPlacedSoFar < numDotsToBePlaced
thisDotBrightness = uint8(minDotBrightness + (maxDotBrightness - minDotBrightness) * rand);
randomRow = randi([1, imageRows- dotRows-1], 1, 1);
randomColumn = randi([1, imageColumns-dotColumns-1], 1, 1);
grayImage(randomRow : randomRow + dotRows - 1, randomColumn:randomColumn+dotColumns-1) = thisDotBrightness;
numDotsPlacedSoFar = numDotsPlacedSoFar + 1;
end
imshow(grayImage, [])
axis('on', 'image')
% impixelinfo; % Mouse around and see values
grid on;
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!