File: view_phase_diff.py

package info (click to toggle)
openstructure 2.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 206,240 kB
  • sloc: cpp: 188,571; python: 36,686; ansic: 34,298; fortran: 3,275; sh: 312; xml: 146; makefile: 29
file content (24 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sys
import math
import ost.img.alg

if len(sys.argv)==2:
  image1=io.LoadImage(sys.argv[1])
  image2=io.LoadImage(sys.argv[2])
else:
  image1=io.LoadImage('square.png')
  image2=io.LoadImage('circle.png')
if image1.GetExtent() != image2.GetExtent():
  raise RuntimeError('The input images should have the same size.')
image1.CenterSpatialOrigin()
image2.CenterSpatialOrigin()
image1.ApplyIP(ost.img.alg.DFT())
image2.ApplyIP(ost.img.alg.DFT())
ex_it=img.ExtentIterator(image1.GetExtent())
diff_image=img.CreateImage(image1.GetExtent())
for pixel in ex_it:
  phase1=img.Phase(image1.GetComplex(pixel))
  phase2=img.Phase(image2.GetComplex(pixel))
  phase_diff=phase1-phase2
  diff_image.SetReal(pixel,180.0*float(phase_diff)/math.pi)
v=gui.CreateDataViewer(diff_image,"Phase difference (in degrees)")