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

In summary, the conversation is about creating a wedge filter in MATLAB to determine the orientation of an ellipse in a centered 2D FFT. The person has tried creating an image with pixel coordinates corresponding to angles, but the results are skewed. They are seeking help and have provided a code snippet for reference.
  • #1
physical101
47
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
  • #2
who knew this existed

[theta,rho] = cart2pol

sorry to be a pain cheers

D
 

1. What is the purpose of replacing pixels with theta of Polar Coordinates in Matlab?

The purpose of replacing pixels with theta of Polar Coordinates in Matlab is to transform the image from Cartesian coordinates to polar coordinates. This can be useful for certain image processing tasks, such as edge detection or feature extraction.

2. How can I replace pixels with theta of Polar Coordinates in Matlab?

To replace pixels with theta of Polar Coordinates in Matlab, you can use the polar2cart function. This function takes in the original image and the desired number of theta angles as inputs, and outputs the transformed image in polar coordinates.

3. Can I adjust the number of theta angles used in the transformation?

Yes, you can adjust the number of theta angles used in the transformation by specifying the desired value when using the polar2cart function. A higher number of theta angles will result in a more detailed transformed image, but it may also take longer to process.

4. Will replacing pixels with theta of Polar Coordinates affect the quality of the image?

The quality of the image may be affected by replacing pixels with theta of Polar Coordinates, as it involves transforming the image from one coordinate system to another. However, the degree of impact on image quality will depend on the specific image and the settings used in the transformation.

5. Can I revert the image back to its original state after replacing pixels with theta of Polar Coordinates?

Yes, you can revert the image back to its original state after replacing pixels with theta of Polar Coordinates by using the cart2polar function. This function takes in the transformed image and the original Cartesian coordinates as inputs, and outputs the image in its original state.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
121
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Programming and Computer Science
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top