Table Of Contents

Previous topic

Modulate Image by Python Function

Next topic

Extracting a subimage

View phase difference

Usage

giplt view_phase_difference.py <image1> <image2>

Description

This scripts displays the phase difference (in degrees) between corresponding pixels in the Fourier Transforms of the two input images, which must be of the same size. The Fourier Transforms honor the origin of the reference system, which is assumed to be at the center of the two images.

Script

import sys
import math
from ost.io import LoadImage
from ost.img import alg

image1=LoadImage(sys.argv[1])
image2=LoadImage(sys.argv[2])
if image1.GetExtent() != image2.GetExtent():
  print 'Error: The input images should have the same size.'
  print sys.exit(0)
image1.CenterSpatialOrigin()
image2.CenterSpatialOrigin()
image1.ApplyIP(alg.DFT())
image2.ApplyIP(alg.DFT())
diff_image=ost.img.CreateImage(image1.GetExtent())
for pixel in image1.GetExtent():
  phase1=ost.img.Phase(image1.GetComplex(pixel))
  phase2=ost.img.Phase(image2.GetComplex(pixel))
  phase_diff=phase1-phase2
  diff_image.SetReal(pixel,180.0*float(phase_diff)/math.pi)
v=Viewer(diff_image)
v.SetName("Phase difference (in degrees)")