# Problem with pixels of filled circle

1 view (last 30 days)
Mario Barrera on 13 Dec 2017
Commented: Mario Barrera on 13 Dec 2017
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;
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

Image Analyst on 13 Dec 2017
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');

Image Analyst on 13 Dec 2017
It saves an image with values of 0 and 1. One gray level is pretty dark, so use [] in imshow() to see it:
imwrite(uint8(circlePixels),'circulo.bmp');
imshow(grayImage, []);
If you didn't want a value of 1 in the circle (like you set it to), then what value did you want?
Mario Barrera on 13 Dec 2017
thanks you :D. imwrite(circlePixels,'circle.bmp'); its work