Openholo  v4.2
Open Source Digital Holographic Library
__init__.py
Go to the documentation of this file.
1 import numpy as np
2 import matplotlib.pyplot as plt
3 
4 __name__ = "ophpy"
5 __version__ = "0.0.4"
6 
7 
8 def fft(f):
9  return np.fft.fftshift(np.fft.fft2(np.fft.fftshift(f)))
10 
11 
12 def ifft(f):
13  return np.fft.fftshift(np.fft.ifft2(np.fft.fftshift(f)))
14 
15 
16 def SSB(ch):
17  """single side band encoding"""
18  height, width = ch.shape
19  a = np.zeros((height, width), dtype='complex128')
20  CH = fft(ch) # fourier transformed image
21  CH = CH[height // 4: (height * 3) // 4, :]
22  a[0:height // 2, :] = CH
23  a[height // 2:, :] = np.conj(CH)
24  return ifft(a)
25 
26 
27 def normalize(arr, type='angle'):
28  """normalize"""
29  if type == 'phase':
30  arrin = np.copy(np.imag(arr))
31  elif type == 'real':
32  arrin = np.copy(np.real(arr))
33  elif type == 'angle':
34  arrin = np.copy(np.angle(arr))
35  elif type == 'amplitude':
36  arrin = np.copy(np.abs(arr))
37  else:
38  arrin = np.copy(arr)
39  # arrin = np.float(arrin)
40  arrin -= np.min(arrin)
41  # arrin = arrin + np.abs(arrin)
42  arrin = arrin / np.max(arrin)
43  return arrin
44 
45 
46 def getRGBImage(R, G, B, fname, type='phase'):
47  """Get RGB image"""
48  h, w = R.shape
49  img = np.zeros((h, w, 3))
50  img[:, :, 0] = normalize(R, type)
51  img[:, :, 1] = normalize(G, type)
52  img[:, :, 2] = normalize(B, type)
53  plt.imsave(fname, img)
54  return img
55 
56 
57 def getMonoImage(ch, fname):
58  """Get Single channel image"""
59  im = normalize(ch, 'phase')
60  phase = fname + '_IM.bmp'
61  plt.imsave(phase, im, cmap='gray')
62  re = normalize(ch, 'real')
63  real = fname + '_RE.bmp'
64  plt.imsave(real, re, cmap='gray')
65  return im, re
def normalize(arr, type='angle')
Definition: __init__.py:27
def getRGBImage(R, G, B, fname, type='phase')
Definition: __init__.py:46
def SSB(ch)
Definition: __init__.py:16
def getMonoImage(ch, fname)
Definition: __init__.py:57
def fft(f)
Definition: __init__.py:8
def ifft(f)
Definition: __init__.py:12