Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Apr 30, 2015 #1
    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=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: Apr 30, 2015
  2. jcsd
  3. May 1, 2015 #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: May 1, 2015
  4. May 2, 2015 #3

    mfb

    User Avatar
    2016 Award

    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.
     
  5. May 2, 2015 #4
    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
  6. May 2, 2015 #5

    mfb

    User Avatar
    2016 Award

    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}##
     
  7. May 2, 2015 #6
    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
  8. May 2, 2015 #7

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    The output of your fft, probably "f1" in your code.
    That's exactly what the fourier transformation is doing.
     
  9. May 3, 2015 #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: May 3, 2015
  10. Jun 9, 2015 #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: Jun 9, 2015
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: How to find phase values at neighboring pixel in an image?
Loading...