How to extract the phase part of an real image properly

Hi everyone,

I am trying to extract the phase part of a 2d image by doing the following method (I want to plot the phase image in the same domain as the input image):

1)redimension the real image to a complex one.

2)perform FFT of the complex input image

2)Extract the phase part of the FFT in the inverse domain

3)take the inverse FFT of it to get beck in the original domain.

I have attached an experiment file. 

The problem I am facing is that after unwrapping the phase part in the inverse domain it gives several NAN points in the image and that leads to a NAN image after performing the IFFT.

Need some advice on how to do it properly and also whether the method is correct or wrong.

 

PhaseFFT.pxp