Creating a random dot pattern with increasing grayscale
27 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2022-8-17
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 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
