Random black and white pixels forming clusters, input proportion of white
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
My knowledge of Matlab is very (very) limited but I am trying to find a code for the following: let's say on a 10*10 image, I would like to be able to enter the porportion of black and white pixels, and generate random images (for instance, generate many random images that are 50% black). The thing is it shouldn't only be pixels, but these should form clusters. One idea would be to define a few random points on the image (five on the example below, at random positions of the 10*10 image). These points would be black and the rest of the image white, so to start. Then around the points, progressively decrease the probability of having a black pixel (this is what I tried to represent with circles around the first point). In the end, it would form clusters and we could give the proportion of white (or black) pixels as an input (e.g. generate random images 50% black). Any help for finding such a code is more than welcome.
I hope this makes sense, please don't hesitate to ask for clarifications. Many thanks in advance for your help.
0 commentaires
Réponses (2)
harjeet singh
le 27 Déc 2015
hello lucy do use this code
clear all
close all
warning off
clc
initial_dots=5;
a=500;
img(1:a,1:a)=1;
img=logical(img);
figure(1)
imshow(img)
drawnow
pos=randint(initial_dots,2,[1 a]);
for i=1:length(pos)
img(pos(i,1),pos(i,2))=0;
end
figure(2)
imshow(img)
drawnow
for i=1:5
for k=1:20
theta=0:k:360;
r=round(pos(i,1) + k*sin(theta));
c=round(pos(i,2) + k*cos(theta));
for j=1:length(r)
if(r(j)>0 && r(j)<a && c(j)>0 && c(j)<a)
img(r(j),c(j))=0;
end
end
end
end
figure(3)
imshow(img)
drawnow
1 commentaire
Image Analyst
le 27 Déc 2015
Good start. What toolbox is randint() in? Can you make it work with the built-in randi() instead? Can you make it work with randomness so that you are not just plopping down a point with 100% certainty? How are you keeping track of the number of points drawn so as to achieve the desired % blackness?
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!