How to find phase values at neighboring pixel in an image?

Tags:
1. Apr 30, 2015

ramdas

I have computed magnitude and phase spectrum of very famous image of cameraman using fft function in MATLAB.Here,we get magnitude and phase spectrum of the whole image. But I want to find phase values of the neighboring pixels .

So if given gray scale image is of dimensions 256*256 and if I want to know phase values say at pixel locations(100,121),(100,122),(100,123) ,How can I find it? Whether it is possible using Fourier Transform or not? If not
,what is the efficient way to do it? Can anybody explain it with (or without) code?

Code (Text):
clc;
clear all;
close all;

%i=rgb2gray(i);
i=uint8(i);

figure,
subplot(1,3,1);imshow(i);
title('Cameraman Gray scale Image');

f1=fft2(i);
f2=log(1+fftshift(f1));

m=abs(f2);
subplot(1,3,2);
imshow(m,[]);
title('Magnitude Spectrum');

phase=angle(f2);
subplot(1,3,3);
imshow(phase,[]);
title('Phase Spectrum');

Last edited: Apr 30, 2015
2. May 1, 2015

ramdas

Why anybody not answering my question? You can give a hint rather. If it is not possible using Fourier transform,what is the other way (wavelet ,laplace etc)

Last edited: May 1, 2015
3. May 2, 2015

Staff: Mentor

I'm not sure if the concept of a phase in the real image (apart from 0) makes sense at all.
The phase of elements of the transformed image is meaningful, of course.

4. May 2, 2015

ramdas

Sir,i am studying fourier transform and want to know importance of PHASES in the images. In
https://en.m.wikipedia.org/wiki/Phase_congruency
it says that in an image EDGES have same phase. I wanted to check it myself with the help of MATLAB or any other way. That's why I wanted check phases of the neighboring pixel are same or not at the edge part in image.

Last edited: May 2, 2015
5. May 2, 2015

Staff: Mentor

Those are not phases of edges or phases of pixels, but phases of the waves you get after the fourier transformation.

You can find the phase of a specific sine wave at a specific location if you know the phase $\phi_0$ at some reference point, the wavelength $\lambda$ and the distance $d$ along the direction of the wave: $\phi = \phi_0 + \frac{2 \pi d}{\lambda}$

6. May 2, 2015

ramdas

Sorry sir but can u explain what you said about "waves we get after fourier transformation " in details giving simple example? Also,is it possible to compute these sine waves mathematically or coding

Last edited: May 2, 2015
7. May 2, 2015

Staff: Mentor

That's exactly what the fourier transformation is doing.

8. May 3, 2015

Fooality

I see you liked my responses last time we talked, thanks. I recommend you forget again about the 2D image, and think in terms of 1D, a function/vector. You can see it as an image with pixels 1d wide.

Every continuous function can be represented as a linear combination of its basis functions, which means each basis function gets multiplied by some number (complex number in case of the FFT) including zero, and then all of them are added up to get the original function. So a certain row of the DFT will be like, in polar form:
cos(t*f) + i*sin(t*f) where f is the frequency described by that row. The FFT will let you know the coefficient to multiply this basis function by to get:
A*(cos(t*f+p) + i*sin(t*f+p))
Where A is correct amplitude, and p is correct starting phase for that frequencies part in your original function/vector/image.
Its written here in polar form, except everyone uses exponential form of complex numbers. If you have any doubt about what this is, than you study complex numbers in polar and exponential form and all will become clear. You can't do this without perfectly getting understanding complex numbers. Drop everything and study them if you don't, its quick to learn.
By discovering the amplitude and phase to apply to each different basis wave, (what the FFT does) applying them and adding them up, you get the original function.

FFT is made for complex number inputs. With real number inputs, like from a picture, its got redundant information, and is symmetrical, with complex conjugate on other side. So you won't find lower/higher frequencies on one end, you'll find them in the middle. (I can't remember which) 2D fft is is 1d fft both ways, vertically and horizontally. So the quickest and dirtiest thing you can do right now to get results is to take a gray square image, take its 2D FFT, define a square perfectly in the middle, and set everything in the square to zero, and transform it back using 2D IFFT. This will give you an image made just of the low/high frequencies that make up your image (again, I can't remember which) and you'll have something you can look at, to start building intuition.

Last edited: May 3, 2015
9. Jun 9, 2015

Fooality

I see you liked that last post. Don't be afraid to write or PM me again, Ramdas. I've been working with DFT's lately and can give you more precise answers if you haven't figured it out for yourself. For me its always a pleasure to connect with people looking for deep answers about this universe we live in, even if I'm not Stephen Hawking. The search for truth is worth in it itself.

Last edited: Jun 9, 2015