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

In summary: 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.
  • #1
ramdas
79
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
  • #2
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:
  • #3
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
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:
  • #5
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
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:
  • #7
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.
 
  • #8
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
  • #9
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:

1. How do I determine the phase value at a neighboring pixel in an image?

To find the phase value at a neighboring pixel in an image, you can use a technique called phase unwrapping. This involves analyzing the phase values at surrounding pixels and using mathematical algorithms to calculate the unwrapped phase value at the neighboring pixel.

2. Can I use a Fourier transform to find phase values at neighboring pixels?

Yes, a Fourier transform can be used to determine the phase values at neighboring pixels in an image. By converting the image to its frequency domain using a Fourier transform, you can then analyze the phase values at different frequencies to find the phase values at neighboring pixels.

3. How do I account for noise when finding phase values at neighboring pixels?

In order to account for noise when finding phase values at neighboring pixels, you can use techniques such as low-pass filtering or noise reduction algorithms. These methods can help to reduce the impact of noise on the phase values and improve the accuracy of the results.

4. Is it possible to find phase values at neighboring pixels in real-time?

Yes, it is possible to find phase values at neighboring pixels in real-time. This can be achieved by using specialized hardware and software designed for real-time analysis, as well as optimizing the algorithms used for phase unwrapping to be more computationally efficient.

5. Can I use machine learning to find phase values at neighboring pixels?

Yes, machine learning can be used to find phase values at neighboring pixels in an image. By training a model on a dataset of images with known phase values, the model can learn to accurately predict the phase values at neighboring pixels in new images.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
19K
Back
Top