MATLAB [Matlab] Replace pixels of an image with theta of Polar Coordinates

AI Thread Summary
The discussion focuses on creating a wedge filter in MATLAB to analyze the orientation of an ellipse in a centered 2D FFT. The user encountered issues when generating an image where pixel values represent angles in degrees, resulting in a skewed output by 45 degrees. The user attempted to use meshgrid and atan functions to calculate angles but faced unexpected results. The code provided includes FFT processing, logarithmic scaling, and median filtering of the FFT output. The user seeks assistance in identifying potential errors in their approach to generating the polar coordinate image and achieving the desired angle representation. The conversation invites contributions from those experienced in MATLAB and image processing to help resolve the issue.
physical101
Messages
41
Reaction score
0
Dear Math and Physics fans

You have always been so helpful in the past and I was hoping that I could call on your expertise once again.

I want to make a wedge filter in MATLAB so I can determine the orientation of the ellipse of a centered 2D fft.

I tried to make an new image where each pixel coordinate corresponded to the angle from the center. I was then going to use a simple for loop to sum of the 2d fft values that were within the bounds of certain angles.

When I tried to make the image which contained the polar coordinates as pixel intensities I got some very odd results back. For instance, the image as a whole seems to be skewed by 45 degrees. If any of you guys have any experience with this could you have a look at my code and tell me where I might be going wrong?

%% do fft

S=fftshift(fft2(fftshift(double(img))));
S = 20*log10(abs(S));
S=medfilt2(S,[5 5]);

%% make image where pixel vals are angles in degrees

sx=size(S);
[x,y]=meshgrid(1:round(sx(2)/2),1:round(sx(1)/2));
[x2,y2]=meshgrid(1:round(sx(2)/2),1:round(sx(1)/2));
[x3,y3]=meshgrid(1:round(sx(2)/2),1:round(sx(1)/2));
[x4,y4]=meshgrid(1:round(sx(2)/2),1:round(sx(1)/2));
t=atan(x./y);
t2=atan(x2./y2);
t3=atan(x3./y3);
t4=atan(x4./y4);
t2=flipud(t2);
t3=fliplr(t3);
t3=flipud(t3);
t4=fliplr(t4);
t5=[t3,t2;t4,t];

tmp1=sin(2.*t5);
tmp2=cos(2.*t5);

ty=((tmp1)./(tmp2));
tr=ty/2;
tr=atan(tr);
tr=tr.*(180/pi);
tr(isnan(tr)==1)=90;


Any help would be really appreciated. Thanking you in advance

D
 
Physics news on Phys.org
who knew this existed

[theta,rho] = cart2pol

sorry to be a pain cheers

D
 

Similar threads

Back
Top