Creating a random dot pattern with increasing grayscale
30 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ahmed Othman
le 17 Août 2022
Réponse apportée : Image Analyst
le 17 Août 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 commentaires
Réponse acceptée
Image Analyst
le 17 Août 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Preview and Device Configuration dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
