Image Transformation to Polar
3 views (last 30 days)
Show older comments
I'm essentially trying to transform an image from cartesian to polar. My script works for an empty grid(i used this to test my function) but the output isnt exactly what I want for the image. I cannot figure out what went wrong in my function. So my grid is supposed to do this: ![yo.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270620/yo.png)
![yo.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270620/yo.png)
And that works fine, but my image goes from this: ![GrayscaleSelfie.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270621/GrayscaleSelfie.png)
![GrayscaleSelfie.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270621/GrayscaleSelfie.png)
to this: ![Rotated.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270622/Rotated.png)
![Rotated.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/270622/Rotated.png)
The chin and teeth get cut out of the image. A quick note, I want to write my own transformation and do not want to use cart2pol or poltocart. I just cannot see where I went wrong in my function(below). The function takes the image as input, an angle of rotation, and a center of which to rotate about. In this case theta = 90 and xc = yc =1. Any thoughts?
function RotateImage = RotateImage(mat,theta, xc, yc)
%Define rotation coordinates
[rY, rX] = meshgrid(0:size(mat,1)-1, 0:size(mat,2)-1); % define the necessary rotation matrix locations in X and Y
y_max = max(max(rY));
%%%%% transform from polar to cartesian %%%%%
%Assuming rX maps to the radius and rY maps to the angle
%ShiftX = rX; %shift center for x
ShiftY = y_max/rY * theta; %shift center for y
X = rX .* cosd(ShiftY); %convert back to cartesian
Y = rX .* sind(ShiftY);
originalX = X+xc; %shift back to center
originalY = Y+yc;
IR = interpolate(mat,originalX,originalY); %interpolate
RotateImage = IR;
end
0 Comments
Answers (1)
See Also
Categories
Find more on Geometric Transformation and Image Registration 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!