Creating a random dot pattern with increasing grayscale
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ahmed Othman
am 17 Aug. 2022
Beantwortet: Image Analyst
am 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 Kommentare
Akzeptierte Antwort
Image Analyst
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
