Borrar filtros
Borrar filtros

How can I uniformly disperse circles in an array?

1 visualización (últimos 30 días)
Eyup Demir
Eyup Demir el 9 de Feb. de 2022
Editada: DGM el 12 de Feb. de 2022
I am trying to generate an BW image that includes uniformly dispersed circles. The number of circles is known (441), dimater of circles (7pixel) and the frame is also known (800x1000 pixel^2), but ofcourse I should be able to change each of them. I tried to locate the spheres centers with linspace on a vector and then reshape vector into an array; however, I got diagonal placement. If you can help me to get BW image similar to the attached image, it is greatly appreciated.

Respuesta aceptada

DGM
DGM el 10 de Feb. de 2022
Editada: DGM el 12 de Feb. de 2022
This does not require any Computer Vision Toolbox functions and outputs a raster image.
d = 7; % dot diameter
s = [800 1000]; % image size [y x]
t = [21 21]; % tiling [y x]
m = s./(t+1)/2; % margin [y x]
% create circular strel
szf = ceil((d-1)/2)*2+1; % odd ceil()
[xx yy] = meshgrid(1:szf);
fk = (((xx-ceil(szf/2))/(szf/2)).^2 + ((yy-ceil(szf/2))/(szf/2)).^2) < 1;
% you could use strel, but it's a pita since it only accepts integer radii
%fk = strel('disk',floor(d/2),0);
A = false(s);
y = round(linspace(1+m(1),s(1)-m(1),t(1)));
x = round(linspace(1+m(2),s(2)-m(2),t(2)));
A(y,x) = true; % the dots are at the intersection of the subscript vectors
B = ~imdilate(A,fk); % dilate
% add a border around the image so it shows up against the white website bg
% this is just for display purposes; omit if undesired
B = padarray(B,[3 3],0,'both');
imshow(B)

Más respuestas (2)

yanqi liu
yanqi liu el 10 de Feb. de 2022
I = uint8(255*ones(800, 1000));
sz = size(I);
th = 7;
[x, y] = meshgrid(linspace(1,sz(2),th), linspace(1,sz(1),th));
x = x(2:end-1,2:end-1);
y = y(2:end-1,2:end-1);
position = [x(:) y(:) 25*ones(length(x(:)),1)];
I2 = insertShape(I,'FilledCircle',position,'Color','black');
I2 = im2bw(I2);
figure; imshow(I2);

David Hill
David Hill el 9 de Feb. de 2022
Editada: David Hill el 9 de Feb. de 2022
[x,y]=meshgrid(1:21);
scatter(x,y,5,'o','MarkerFaceColor','k','MarkerEdgeColor','k');%change marker size for different size circles
ax = gca;
ax.XLim = [0 22];
ax.YLim = [0 22];
ax.Box='on';
ax.XTick=[];
ax.YTick=[];
ax.XTickLabel='';
ax.YTickLabel='';

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by