OpenStructure
Loading...
Searching...
No Matches
view_phase_diff.py

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

Usage:

dng view_phase_diff.py <image1> <image2>



1import sys
2import math
3import ost.img.alg
4
5if len(sys.argv)==2:
6 image1=io.LoadImage(sys.argv[1])
7 image2=io.LoadImage(sys.argv[2])
8else:
9 image1=io.LoadImage('square.png')
10 image2=io.LoadImage('circle.png')
11if image1.GetExtent() != image2.GetExtent():
12 raise RuntimeError('The input images should have the same size.')
13image1.CenterSpatialOrigin()
14image2.CenterSpatialOrigin()
15image1.ApplyIP(ost.img.alg.DFT())
16image2.ApplyIP(ost.img.alg.DFT())
17ex_it=img.ExtentIterator(image1.GetExtent())
18diff_image=img.CreateImage(image1.GetExtent())
19for pixel in ex_it:
20 phase1=img.Phase(image1.GetComplex(pixel))
21 phase2=img.Phase(image2.GetComplex(pixel))
22 phase_diff=phase1-phase2
23 diff_image.SetReal(pixel,180.0*float(phase_diff)/math.pi)
24v=gui.CreateDataViewer(diff_image,"Phase difference (in degrees)")