How to make raster circle with arbitrary high resolution?

Is it possible to plot a vectorized circle in MATLAB and save it to a pixelized raster figure with arbitrary high resolution?
In fact I need a pixel, if the curve of the circle has any point in that pixel.

Antworten (1)

Image Analyst
Image Analyst am 23 Feb. 2019

0 Stimmen

Of course. It's in the FAQ: Click here for the FAQ
Adjust the image size parameters in the code to get more or less resolution.

3 Kommentare

Mr M.
Mr M. am 23 Feb. 2019
Bearbeitet: Mr M. am 23 Feb. 2019
Yes, but I want to control the algorithm, as I mentioned above. Or use an approriate image format. What I want: black pixel if the circumference of the circle gos thru that pixel (small square), and white elsewhere. No smoothing, no gray pixels, etc.
meshgrid and circlePixels = (rowsInImage - centerY).^2 + (columnsInImage - centerX).^2 <= radius.^2; is not useful for me, because this associate the center of the pixel to the pixel.
I don't think you tried to use/adapt the FAQ at all. I did and it works fine. There is no smoothing and you DO have control over the algorithm by assigning values for the center, radius, and number of points along the circumference.
See code below:
% Create image of size 2000 by 2000
myImage = zeros(2000, 2000, 'uint8');
% Now use FAQ but change the center to (1600, 800) and the radius to 350.
xCenter = 1600;
yCenter = 800;
radius = 350;
% Circumference for a circle of radius 350 should be 2*pi*r = 2199.
% To have no gaps in the circle we need to make sure we have at least as many coordinates
% in x and y as there are around the circumference of the circle.
% Make it double that just to make extra sure there are no gaps in the circle.
theta = linspace(0, 2*pi, round(4 * pi * radius));
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
plot(x, y);
axis square;
grid on;
% Write those (x,y) into the image with gray level 255.
for k = 1 : length(x)
row = round(y(k));
col = round(x(k));
myImage(row, col) = 255;
end
% Display the image. It may appear as though there are gaps in the circle
% due to subsampling for display but examine the image in the variable inspector
% and you'll see there are no gaps/breaks in the circle.
imshow(myImage);
axis('on', 'image');
Adapt it for your own values.
Sorry but I don't know what "associate the center of the pixel to the pixel" means.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 23 Feb. 2019

Kommentiert:

am 23 Feb. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by