Changing semi circle image from Cartesian to Polar coordinate
4 views (last 30 days)
Show older comments
fatemeh mazinani
on 20 Feb 2022
Commented: fatemeh mazinani
on 23 Feb 2022
Hi Folks,
I want to create an Image of 2 semi circle with (R1 and R2) and than convert the cordinate from cart to polar.
below is the code that i used to create circle but i dont know how to expand it to 2 semi circle.
Can you please help me with that?
% First create the image.
imageSizeX = 144;
imageSizeY = 144;
[columnsInImage rowsInImage] = meshgrid(1:1:imageSizeX, 1:1:imageSizeY);
% Next create the logical circle in the image
centerX = 72;
centerY = 72;
r = 64; %radius
circlePixels =(rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= r.^2;
% circlePixels is a 2D "logical" array.
%convert logical to number
img1 = double(circlePixels);
% Now, display it.
imagesc(img1);
set(gca,'YDir','normal') % invert Y-axis on images
imageCenter=[72,72];
viscircles(imageCenter,64,'EdgeColor','w','LineWidth',1); % Draw circles line with white color line and width line is 5
grid on
grid minor
save ('img1.mat'); % save ref. image as img1.mat file for analysis
0 Comments
Accepted Answer
Simon Chan
on 21 Feb 2022
Determine the perimeter for half circle and then connecting the end points with a straight line.
And you may change the angle of rotation in variable 'angstart'.
clear; clc;
imageSizeX = 144;
imageSizeY = 144;
% Next create the logical circle in the image
centerX = 72;
centerY = 72;
r = 64;
%
Nz = max(imageSizeX, imageSizeY);
angstart = pi/3; % Please change this value for different angles
theta = linspace(angstart,angstart+pi,Nz);
[x,y] = pol2cart(theta,repelem(r,1,Nz));
xcir = round(x + centerX);
ycir = round(y + centerY);
img = false(imageSizeY,imageSizeX);
for k = 1:Nz
img(ycir(k),xcir(k))=true;
end
% Determine a line connecting the first and last point of the
% semi-circle
line_rho = -r:1:r;
slope = atand((ycir(end)-ycir(1))/(xcir(end)-xcir(1)))*pi/180;
line_theta = repelem(slope,1,2*r+1);
[x,y] = pol2cart(line_theta,line_rho);
xln = round(x + centerX);
yln = round(y + centerY);
for k = 1:2*r+1
img(yln(k),xln(k))=true;
end
%
img1 = double(img);
% Now, display it.
imagesc(img1);
set(gca,'YDir','normal') % invert Y-axis on images
imageCenter=[72,72];
%viscircles(imageCenter,64,'EdgeColor','w','LineWidth',1); % Draw circles line with white color line and width line is 5
grid on
grid minor
axis image
More Answers (0)
See Also
Categories
Find more on Polar 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!