MATLAB: Problem with pixels of filled circle

circlepixels

I'm using a code obtained from to create a circle of 200 pixels radius . When I open the image with another program (paint or adobe for example) to verify that the number of pixels is 200, I find variations of more than 30 pixels in terms of length. The code is:
imageSizeX = 400;
imageSizeY = 400;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 200;
centerY = 200;
radius = 200;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels) ;
colormap([1 1 1; 0 0 0]);
axis off;
saveas(image(circlePixels),'circulo.bmp')
What is the reason?
Thanks

Best Answer

It's because you're not saving the image. You're saving a screenshot, and who knows how big that is? You can adjust the size to whatever you want. Just because the underlying image has a radius of 200 doesn't mean that the radius on the display is 200 pixels. In fact you can change it just by dragging the corner of the window. What you want to do is to call imwrite() to save the actual image, not saveas() to save the screenshot:
imwrite(uint8(circlePixels),'circulo.bmp');