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

Click For Summary
SUMMARY

The discussion focuses on creating a wedge filter in MATLAB to analyze the orientation of an ellipse from a centered 2D FFT. The user encountered issues when attempting to replace pixel values with angles derived from polar coordinates, resulting in a skewed image. Key MATLAB functions used include fft2, fftshift, and medfilt2. The user seeks assistance in correcting the angle mapping process to achieve accurate pixel representation.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of 2D Fast Fourier Transform (FFT) concepts
  • Knowledge of polar coordinates and their conversion from Cartesian coordinates
  • Experience with image processing techniques in MATLAB
NEXT STEPS
  • Explore MATLAB's cart2pol function for converting Cartesian coordinates to polar coordinates
  • Research techniques for correcting skewed images in MATLAB
  • Learn about advanced image filtering methods in MATLAB, such as medfilt2
  • Investigate the impact of angle mapping on image processing results in MATLAB
USEFUL FOR

This discussion is beneficial for MATLAB users, image processing enthusiasts, and researchers analyzing 2D FFT data, particularly those interested in polar coordinate transformations and image filtering techniques.

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

Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
31K
  • · Replies 13 ·
Replies
13
Views
4K