How to make raster circle with arbitrary high resolution?

조회 수: 5 (최근 30일)
Mr M.
Mr M. 2019년 2월 23일
댓글: Image Analyst 2019년 2월 23일
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에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by