How can i create an image with randomly distributed filled circles (not only the contours), having different colours?
Afficher commentaires plus anciens
hello, i have been trying to create an image with randomly distributed circles, (that i have to analyze with other codes at a later stage) using this code:
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
circles=[];
X=[];
Y=[];
radii=[];
for i=1:10
n =rand(1);
centerX(i) = 320*n;
X=[X centerX(i)];
centerY(i) = 240*n;
Y=[Y centerY(i)];
radius(i) = 100*n;
radii=[radii radius(i)];
end
circles=[];
for i=1:10
circlePixels(:,:,i) = (rowsInImage - Y(i)).^2 ...
+ (columnsInImage - X(i)).^2 <= radius(i).^2;
circles=[circles circlePixels(:,:,i)];
end
image(circlePixels(:,:,1:10)) ;
colormap([0 0 0; 0.5 0.5 0.5]);
However it seems that this is the wrong way since i always get the error. Does anyone have any idea of how i can do this?
Réponses (1)
You could try using viscircles
% image size
xres = 640;
yres = 480;
% radii & centers
n = 200;
rr = rand(n,1).*5
xc = rand(n,1).*xres;
yc = rand(n,1).*yres;
% Circles
viscircles([xc,yc],rr)
xlim([0 xres])
ylim([0 yres])
set(gca,'xcolor','none','ycolor','none')
% Save as image
I = getframe(gca)
% Show image
imshow(I.cdata)
Catégories
En savoir plus sur Lighting, Transparency, and Shading dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!