MATLAB fourier problems

Hardware, software, geek stuff

Moderators: laterna, Fridmarr, Worldie, Aergis, Sabindeus, PsiVen

MATLAB fourier problems

Postby Arjuna » Mon Jul 11, 2011 6:55 am

Hey all!

I'm sitting working on a thingy, and using MATLAB is required. My problem is that we never learned it in school and I am not that good at MATLAB...yet...

I'm trying to show the fourier transform of an image named hex.gif, but i keep getting two completely different pictures from "image" and "pcolor".

Here's my code for reference: (with a few "extras")
Code: Select all
A = (imread('hex.gif','gif'));
sz = size(A);
N = sz(1);
M = sz(2);
lambda = 600e-9;
%f = 16.5e-3;
W = 0.04;
f = 0.1;
%W = 2e-3;
%W = 1;
I = abs((fftshift(fft2(A))));
%I = (fftshift(double(fft2(A)))).^2;
x = linspace(-lambda*f*N/(2*W), lambda*f*N/(2*W), N);
y = linspace(-lambda*f*M/(2*W), lambda*f*M/(2*W), M);
%x = linspace(-lambda*f*187/(2*W), lambda*f*187/(2*W), 187);
%y = linspace(-lambda*f*187/(2*W), lambda*f*187/(2*W), 187);
%F= abs(I);

figure(1);
image(I)
figure(2);
pcolor(x,y,I)
figure(3);
image(A)


I would appreciate any help in the matter! :)
HUZZAH! How many points do I receive? :D
User avatar
Arjuna
 
Posts: 1855
Joined: Tue Aug 14, 2007 3:26 am

Re: MATLAB fourier problems

Postby theckhd » Mon Jul 11, 2011 7:29 am

It might be a simple indexing problem. image() will index elements from the top left hand of the picture (so the top left corner is pixel 1,1, the bottom left pixel is M,1, the top right pixel is 1,N, and the bottom right pixel is M,N). pcolor(x,y,z) will create a pseudocolor plot using coordinates x and y, which in your case are defined in the normal form (-x:x, -y:y). That will flip the y-axis, unless I'm mistaken.

It's hard to tell without seeing your image though; A quick test of a rect function seems to work properly for me.

Code: Select all
x=-50:50;
y=-50:50;
[x y]=meshgrid(x,y);
z=(abs(x)<10).*(abs(y)<10);
I = abs((fftshift(fft2(z))));
I(19:21,19:21)=250; %arbitrarily set one section to be asymmetric
figure(1);image(I)
figure(2);pcolor(x,y,I) %note the asymmetric point is in the wrong quadrant
figure(3);pcolor(x,y,flipud(I)) %flipping the image on the vertical makes pcolor() match image()
"Theck, Bringer of Numbers and Pounding Headaches," courtesy of Grehn|Skipjack.
MATLAB 5.x, Simcraft 6.x, Call to Arms 6.0, Talent Spec & Glyph Guide 5.x, Blog: Sacred Duty
User avatar
theckhd
Moderator
 
Posts: 7972
Joined: Thu Jul 31, 2008 3:06 pm
Location: Harrisburg, PA

Re: MATLAB fourier problems

Postby Arjuna » Mon Jul 11, 2011 7:41 am

Image is a little hex with triangles inside, nothing too advanced.
Image
Unfortunately I can't try it out now, I don't have matlab here on this comp. I'll have to sit with it tomorrow though and try that out, want a nice picture for when I'm gonna do the inverse...

Last time I tried my code I got a nice picture of a fourier transform from "image", but "pcolor" gave a black image with a very VERY weak fourier transform in the middle that only could be seen if you zoomed in...
HUZZAH! How many points do I receive? :D
User avatar
Arjuna
 
Posts: 1855
Joined: Tue Aug 14, 2007 3:26 am

Re: MATLAB fourier problems

Postby theckhd » Mon Jul 11, 2011 3:24 pm

They're giving you the same plot, it's just a difference in how image and pcolor handle the colormap scaling.

max(max(I))=23081, but if you show the colorbar for the image() and pcolor() versions, the image() call is capping the colormap at around 70, while the pcolor() call is setting the upper bound at the max (23081).

Try adding this line after your pcolor() call:
Code: Select all
caxis([0 70])

That should cap the pcolor() at roughly the same value, and then the two will look the same.
"Theck, Bringer of Numbers and Pounding Headaches," courtesy of Grehn|Skipjack.
MATLAB 5.x, Simcraft 6.x, Call to Arms 6.0, Talent Spec & Glyph Guide 5.x, Blog: Sacred Duty
User avatar
theckhd
Moderator
 
Posts: 7972
Joined: Thu Jul 31, 2008 3:06 pm
Location: Harrisburg, PA

Re: MATLAB fourier problems

Postby Arjuna » Mon Jul 11, 2011 5:27 pm

thank you, will try tomorrow! :)
HUZZAH! How many points do I receive? :D
User avatar
Arjuna
 
Posts: 1855
Joined: Tue Aug 14, 2007 3:26 am

Re: MATLAB fourier problems

Postby Arjuna » Tue Jul 12, 2011 2:45 pm

Whooo!!! Worked like a charm theck! :D Thank you a ton!

But as one problem is solved, another arises...but oh well, there is a day tomorrow and it's gonna be full of hairpulling and cursing, hahaha
HUZZAH! How many points do I receive? :D
User avatar
Arjuna
 
Posts: 1855
Joined: Tue Aug 14, 2007 3:26 am


Return to Tech Stuff

Who is online

Users browsing this forum: Google [Bot] and 0 guests

Who is online

In total there is 1 user online :: 1 registered, 0 hidden and 0 guests (based on users active over the past 5 minutes)
Most users ever online was 380 on Tue Oct 14, 2008 6:28 pm

Users browsing this forum: Google [Bot] and 0 guests