How to make raster circle with arbitrary high resolution?

4 次查看(过去 30 天)
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.

回答(1 个)

Image Analyst
Image Analyst 2019-2-23
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 个评论
Mr M.
Mr M. 2019-2-23
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.
Image Analyst
Image Analyst 2019-2-23
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by