How to draw a disk of given center and radius ?

1 view (last 30 days)
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)

Accepted Answer

Image Analyst
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
Gunjan Gautam
Gunjan Gautam on 25 Sep 2017
Edited: Gunjan Gautam on 25 Sep 2017
Thanks for the prompt response. I would be grateful if you could be more specific. Can I control having more pixels as it is generated by MATLAB code? Ultimately, I want a smoother disk because it is jeopardizing my results.
Image Analyst
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.

Sign in to comment.

More Answers (1)

shamookh alqahtani
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
Image Analyst on 18 Feb 2020
How is this different than the original code the poster posted? What did you change?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!