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

AI Thread Summary
The discussion centers on extracting phase values of neighboring pixels from a grayscale image using the Fourier Transform in MATLAB. The user has computed the magnitude and phase spectrum of an image but seeks to understand the phase values at specific pixel locations. It is noted that while the phase of transformed image elements is meaningful, the concept of phase in the original image may not be directly applicable. The conversation emphasizes the importance of understanding complex numbers and the relationship between the Fourier Transform and sine waves. Suggestions include exploring the 1D representation of images and manipulating the frequency domain to gain insights into phase relationships.
ramdas
Messages
78
Reaction score
0
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:
clc;
clear all;
close all;

i=imread('C:\Users\RK\Desktop\cameraman.gif');
%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:
Technology news on Phys.org
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:
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.
 
mfb said:
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.
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:
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}##
 
mfb said:
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}##
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:
ramdas said:
"waves we get after Fourier transformation "
The output of your fft, probably "f1" in your code.
ramdas said:
Also,is it possible to compute these sine waves mathematically or coding
That's exactly what the Fourier transformation is doing.
 
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:
  • Like
Likes ramdas
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:

Similar threads

Replies
1
Views
2K
Replies
4
Views
3K
Replies
7
Views
4K
Replies
1
Views
2K
Replies
2
Views
20K
Back
Top