Changing semi circle image from Cartesian to Polar coordinate
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Simon Chan
2022 年 2 月 21 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Geographic Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
