creating multiple circles inside an array
Show older comments
Hi - this is some code that I found of the matlabs wiki. I am trying to modify it to suit my use and am struggling greatly to achieve the required outcome.
Basically this creates 1 circle within an array. The circle is designated as 1s and everything outside the circle are 0s.
However, I have an unknown amount of circles (similar radi but different X and Y for centers)
What I want to do is to create multiple circles within this array. Eventually hopefully, I will return a final array that has a 1 where a circle overlaps and 0 where no circle has overlapped.
Would the following code be modifiable or would I need a different approach?
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 240;
radius = 100;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels) ;
colormap([0 0 0; 1 1 1]);
title('Binary image of a circle');
Accepted Answer
More Answers (2)
Image Analyst
on 25 Mar 2020
0 votes
Search the forum for the tag "circle packing" and you'll find code. CLICK HERE
darova
on 25 Mar 2020
Try imdilate
I0 = false(1000); % create logical matrix
ind = randperm(1000^2,7); % random position to place
I0(ind) = 1; % place 'one'
I1 = imdilate(I0,circlePixels); % place circles
imshow(I1)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!