How to make raster circle with arbitrary high resolution?
5 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Image Analyst
on 23 Feb 2019
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 Comments
Image Analyst
on 23 Feb 2019
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.
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!