How to draw a disk of given center and radius ?
1 view (last 30 days)
Show older comments
Gunjan Gautam
on 25 Sep 2017
Commented: Image Analyst
on 18 Feb 2020
I have computed the center and radius and now I want to draw a white disk using these parameters on a black background. I tried something like below but its generating a flat edge in four directions. It is kind of urgent to compare the results so any help would be appreciated. I have attached two images to keep my point. Please zoom the images in order to see what am I claiming.
[imageSizeY,imageSizeX,d] = size(imgimg);
[columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
centerX = floor(centroid(1));
centerY = floor(centroid(2));
radius = ceil(radii);
circlePixels = (rowsInImage - centerY).^2 + (columnsInImage - centerX).^2 <= radius.^2;
circlePixels = mat2gray(circlePixels);
%figure, imshow(circlePixels);
formatSpec_org = 'Proposed%d.png';
strProposed1 = sprintf(formatSpec_org, x);
strProposed2 = 'OutputFolder\';
s_P = strcat(strProposed2,strProposed1);
imwrite(circlePixels,s_P)
0 Comments
Accepted Answer
Image Analyst
on 25 Sep 2017
Those are simply quantization/digitization errors. If you want a smoother circle, you need to have more pixels in your image. A finer resolution will give you smoother edges on your circle with smaller flat edges along the horizontal and vertical sides.
2 Comments
Image Analyst
on 25 Sep 2017
I don't know what imgimg is. Why don't you try making it bigger, like
imgimg = imresize(imgimg, 3); % Increase by a factor of 3.
Then follow with the rest of your code, making adjustments to the center and radius as needed.
More Answers (1)
shamookh alqahtani
on 18 Feb 2020
[imageSizeY,imageSizeX,d] = size(imgimg);
[columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
centerX = floor(centroid(1));
centerY = floor(centroid(2));
radius = ceil(radii);
circlePixels = (rowsInImage - centerY).^2 + (columnsInImage - centerX).^2 <= radius.^2;
circlePixels = mat2gray(circlePixels);
%figure, imshow(circlePixels);
formatSpec_org = 'Proposed%d.png';
strProposed1 = sprintf(formatSpec_org, x);
strProposed2 = 'OutputFolder\';
s_P = strcat(strProposed2,strProposed1);
imwrite(circlePixels,s_P)
1 Comment
Image Analyst
on 18 Feb 2020
How is this different than the original code the poster posted? What did you change?
See Also
Categories
Find more on Filter Analysis 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!