MATLAB fourier problems
Moderators: laterna, Fridmarr, Worldie, Aergis, Sabindeus, PsiVen
6 posts
• Page 1 of 1
MATLAB fourier problems
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")
I would appreciate any help in the matter!
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? 
-

Arjuna - Posts: 1811
- Joined: Tue Aug 14, 2007 3:26 am
Re: MATLAB fourier problems
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.
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, Call to Arms 5.x, Talent Spec & Glyph Guide 5.x, Blog: Sacred Duty
MATLAB 5.x, Call to Arms 5.x, Talent Spec & Glyph Guide 5.x, Blog: Sacred Duty
-

theckhd - Moderator
- Posts: 7454
- Joined: Thu Jul 31, 2008 3:06 pm
- Location: Harrisburg, PA
Re: MATLAB fourier problems
Image is a little hex with triangles inside, nothing too advanced.

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...

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? 
-

Arjuna - Posts: 1811
- Joined: Tue Aug 14, 2007 3:26 am
Re: MATLAB fourier problems
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:
That should cap the pcolor() at roughly the same value, and then the two will look the same.
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, Call to Arms 5.x, Talent Spec & Glyph Guide 5.x, Blog: Sacred Duty
MATLAB 5.x, Call to Arms 5.x, Talent Spec & Glyph Guide 5.x, Blog: Sacred Duty
-

theckhd - Moderator
- Posts: 7454
- Joined: Thu Jul 31, 2008 3:06 pm
- Location: Harrisburg, PA
Re: MATLAB fourier problems
Whooo!!! Worked like a charm theck!
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
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? 
-

Arjuna - Posts: 1811
- Joined: Tue Aug 14, 2007 3:26 am
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest