Openholo  beta 2.0
Open Source Digital Holographic Library
ophSigPU Class Reference
Inheritance diagram for ophSigPU:
Inheritance graph

Public Member Functions

bool setPUparam (int maxBoxRadius)
 Set parameters for Goldstein branchcut algorithm. More...
 
bool loadPhaseOriginal (const char *fname, int bitpixel)
 Load original wrapped phase data. More...
 
bool runPU (void)
 Run phase unwrapping algorithm. More...
 
bool savePhaseUnwrapped (const char *fname)
 Save the unwrapped phase data to image file. More...
 
bool readConfig (const char *fname)
 Read configure file. More...
 
bool setPUparam (int maxBoxRadius)
 Set parameters for Goldstein branchcut algorithm. More...
 
bool loadPhaseOriginal (const char *fname, int bitpixel)
 Load original wrapped phase data. More...
 
bool runPU (void)
 Run phase unwrapping algorithm. More...
 
bool savePhaseUnwrapped (const char *fname)
 Save the unwrapped phase data to image file. More...
 
bool readConfig (const char *fname)
 Read configure file. More...
 
bool load (const char *real, const char *imag)
 Load bmp or bin file. More...
 
bool load (const char *real, const char *imag)
 Load bmp or bin file. More...
 
bool save (const char *real, const char *imag)
 Save data as bmp or bin file. More...
 
bool save (const char *real, const char *imag)
 Save data as bmp or bin file. More...
 
int loadAsOhc (const char *fname)
 Function to read OHC file. More...
 
int loadAsOhc (const char *fname)
 Function to read OHC file. More...
 
int saveAsOhc (const char *fname)
 Function to write OHC file. More...
 
int saveAsOhc (const char *fname)
 Function to write OHC file. More...
 
bool sigConvertOffaxis ()
 Function for Convert complex hologram to off-axis hologram . More...
 
bool sigConvertOffaxis ()
 Function for Convert complex hologram to off-axis hologram . More...
 
bool sigConvertHPO ()
 Function for convert complex hologram to horizontal parallax only hologram . More...
 
bool sigConvertHPO ()
 Function for convert complex hologram to horizontal parallax only hologram . More...
 
bool sigConvertCAC (double red, double green, double blue)
 Function for Chromatic aberration compensation filter . More...
 
bool sigConvertCAC (double red, double green, double blue)
 Function for Chromatic aberration compensation filter . More...
 
bool propagationHolo (float depth)
 Function for Chromatic aberration compensation filter. More...
 
OphComplexField propagationHolo (OphComplexField complexH, float depth)
 Function for propagation hologram. More...
 
bool propagationHolo (float depth)
 Function for Chromatic aberration compensation filter. More...
 
OphComplexField propagationHolo (OphComplexField complexH, float depth)
 Function for propagation hologram. More...
 
double sigGetParamAT ()
 Extraction of distance parameter using axis transfomation . More...
 
double sigGetParamAT ()
 Extraction of distance parameter using axis transfomation . More...
 
double sigGetParamSF (float zMax, float zMin, int sampN, float th)
 Extraction of distance parameter using sharpness functions . More...
 
double sigGetParamSF (float zMax, float zMin, int sampN, float th)
 Extraction of distance parameter using sharpness functions . More...
 
bool getComplexHFromPSDH (const char *fname0, const char *fname90, const char *fname180, const char *fname270)
 Extraction of complex field from 4 phase shifted interference patterns . More...
 
bool getComplexHFromPSDH (const char *fname0, const char *fname90, const char *fname180, const char *fname270)
 Extraction of complex field from 4 phase shifted interference patterns . More...
 
virtual int saveAsImg (const char *fname, uint8_t bitsperpixel, uchar *src, int pic_width, int pic_height)
 Function for creating image files. More...
 
virtual int saveAsImg (const char *fname, uint8_t bitsperpixel, uchar *src, int pic_width, int pic_height)
 Function for creating image files. More...
 
virtual uchar * loadAsImg (const char *fname)
 Function for loading image files. More...
 
virtual uchar * loadAsImg (const char *fname)
 Function for loading image files. More...
 
unsigned long addRef (void)
 If referenced this(Base's child, not abstract class) instance, must call this method. More...
 
unsigned long addRef (void)
 If referenced this(Base's child, not abstract class) instance, must call this method. More...
 
unsigned long release (void)
 Call release() when reference is finished. More...
 
unsigned long release (void)
 Call release() when reference is finished. More...
 

Protected Member Functions

vector< Real > linspace (double first, double last, int len)
 Generate linearly spaced vector. More...
 
vector< Real > linspace (double first, double last, int len)
 Generate linearly spaced vector. More...
 
template<typename T >
void linInterp (vector< T > &X, matrix< Complex< T >> &in, vector< T > &Xq, matrix< Complex< T >> &out)
 Function for Linear interpolation 1D. More...
 
template<typename T >
void linInterp (vector< T > &X, matrix< Complex< T >> &in, vector< T > &Xq, matrix< Complex< T >> &out)
 Function for Linear interpolation 1D. More...
 
template<typename T >
void absMat (matrix< Complex< T >> &src, matrix< T > &dst)
 Function for extracts Complex magnitude value. More...
 
template<typename T >
void absMat (matrix< T > &src, matrix< T > &dst)
 Function for extracts real absolute value. More...
 
template<typename T >
void absMat (matrix< Complex< T >> &src, matrix< T > &dst)
 Function for extracts Complex magnitude value. More...
 
template<typename T >
void absMat (matrix< T > &src, matrix< T > &dst)
 Function for extracts real absolute value. More...
 
template<typename T >
void angleMat (matrix< Complex< T >> &src, matrix< T > &dst)
 Function for extracts Complex phase value. More...
 
template<typename T >
void angleMat (matrix< Complex< T >> &src, matrix< T > &dst)
 Function for extracts Complex phase value. More...
 
template<typename T >
void conjMat (matrix< Complex< T >> &src, matrix< Complex< T >> &dst)
 Function for extracts Complex conjugate value. More...
 
template<typename T >
void conjMat (matrix< Complex< T >> &src, matrix< Complex< T >> &dst)
 Function for extracts Complex conjugate value. More...
 
template<typename T >
void expMat (matrix< Complex< T >> &src, matrix< Complex< T >> &dst)
 Function for returns exponent ex. More...
 
template<typename T >
void expMat (matrix< T > &src, matrix< T > &dst)
 Function for returns exponent e(x), where x is complex number. More...
 
template<typename T >
void expMat (matrix< Complex< T >> &src, matrix< Complex< T >> &dst)
 Function for returns exponent ex. More...
 
template<typename T >
void expMat (matrix< T > &src, matrix< T > &dst)
 Function for returns exponent e(x), where x is complex number. More...
 
template<typename T >
void meanOfMat (matrix< T > &input, double &output)
 Function for returns exponent e(x), where x is real number. More...
 
template<typename T >
void meanOfMat (matrix< T > &input, double &output)
 Function for returns exponent e(x), where x is real number. More...
 
template<typename T >
Real maxOfMat (matrix< T > &src)
 Function for extracts max of matrix. More...
 
template<typename T >
Real maxOfMat (matrix< T > &src)
 Function for extracts max of matrix. More...
 
template<typename T >
Real minOfMat (matrix< T > &src)
 Function for extracts min of matrix. More...
 
template<typename T >
Real minOfMat (matrix< T > &src)
 Function for extracts min of matrix. More...
 
template<typename T >
void meshgrid (vector< T > &src1, vector< T > &src2, matrix< T > &dst1, matrix< T > &dst2)
 Function for returns 2d matrix based on vector src1, src2. More...
 
template<typename T >
void meshgrid (vector< T > &src1, vector< T > &src2, matrix< T > &dst1, matrix< T > &dst2)
 Function for returns 2d matrix based on vector src1, src2. More...
 
template<typename T >
void fft1 (matrix< Complex< T >> &src, matrix< Complex< T >> &dst, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Function for Fast Fourier transform 1D. More...
 
template<typename T >
void fft1 (matrix< Complex< T >> &src, matrix< Complex< T >> &dst, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Function for Fast Fourier transform 1D. More...
 
void fft1 (int n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 1-dimension operations inside Openholo. More...
 
template<typename T >
void fft2 (matrix< Complex< T >> &src, matrix< Complex< T >> &dst, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Function for Fast Fourier transform 2D. More...
 
template<typename T >
void fft2 (matrix< Complex< T >> &src, matrix< Complex< T >> &dst, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Function for Fast Fourier transform 2D. More...
 
void fft2 (oph::ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 2-dimension operations inside Openholo. More...
 
template<typename T >
void fftShift (matrix< Complex< T >> &src, matrix< Complex< T >> &dst)
 Function for Shift zero-frequency component to center of spectrum. More...
 
template<typename T >
void fftShift (matrix< Complex< T >> &src, matrix< Complex< T >> &dst)
 Function for Shift zero-frequency component to center of spectrum. More...
 
void fftShift (int nx, int ny, Complex< Real > *input, Complex< Real > *output)
 Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom-left. More...
 
virtual void ophFree (void)
 Pure virtual function for override in child classes. More...
 
virtual void ophFree (void)
 Pure virtual function for override in child classes. More...
 
int checkExtension (const char *fname, const char *ext)
 Functions for extension checking. More...
 
int checkExtension (const char *fname, const char *ext)
 Functions for extension checking. More...
 
int loadAsImgUpSideDown (const char *fname, uchar *dst)
 Function for loading image files | Output image data upside down. More...
 
int loadAsImgUpSideDown (const char *fname, uchar *dst)
 Function for loading image files | Output image data upside down. More...
 
int getImgSize (int &w, int &h, int &bytesperpixel, const char *file_name)
 Function for getting the image size. More...
 
int getImgSize (int &w, int &h, int &bytesperpixel, const char *file_name)
 Function for getting the image size. More...
 
void imgScaleBilnear (unsigned char *src, unsigned char *dst, int w, int h, int neww, int newh)
 Function for change image size. More...
 
void imgScaleBilnear (unsigned char *src, unsigned char *dst, int w, int h, int neww, int newh)
 Function for change image size. More...
 
void convertToFormatGray8 (unsigned char *src, unsigned char *dst, int w, int h, int bytesperpixel)
 Function for convert image format to gray8. More...
 
void convertToFormatGray8 (unsigned char *src, unsigned char *dst, int w, int h, int bytesperpixel)
 Function for convert image format to gray8. More...
 
void fft3 (oph::ivec3 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 3-dimension operations inside Openholo. More...
 
void fft3 (oph::ivec3 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 3-dimension operations inside Openholo. More...
 
void fftExecute (Complex< Real > *out)
 Execution functions to be called after fft1, fft2, and fft3. More...
 
void fftExecute (Complex< Real > *out)
 Execution functions to be called after fft1, fft2, and fft3. More...
 
void fftwShift (Complex< Real > *src, Complex< Real > *dst, int nx, int ny, int type, bool bNormalized=false)
 Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. More...
 
void fftwShift (Complex< Real > *src, Complex< Real > *dst, int nx, int ny, int type, bool bNormalized=false)
 Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. More...
 
void setPixelNumberOHC (const ivec2 pixel_number)
 getter/setter for OHC file read and write More...
 
void setPixelNumberOHC (const ivec2 pixel_number)
 getter/setter for OHC file read and write More...
 
void addWaveLengthNComplexFieldDataOHC (const Real wavelength, const OphComplexField &complex_field)
 Function to add ComplexField when adding wavelength data. More...
 
void addWaveLengthNComplexFieldDataOHC (const Real wavelength, const OphComplexField &complex_field)
 Function to add ComplexField when adding wavelength data. More...
 

Protected Attributes

ImgEncoderOhc * OHC_encoder
 OHC file format Variables for read and write. More...
 

Detailed Description

Author

Definition at line 26 of file ophsig/src/ophSigPU.h.

Member Function Documentation

◆ absMat() [1/4]

template<typename T >
void ophSig::absMat ( matrix< Complex< T >> &  src,
matrix< T > &  dst 
)
inlineprotectedinherited

Function for extracts Complex magnitude value.

Parameters
srcinput signal
dstoutput signal

Definition at line 59 of file ophSig.cpp.

59  {
60  if (src.size != dst.size) {
61  dst.resize(src.size[_X], src.size[_Y]);
62  }
63  for (int i = 0; i < src.size[_X]; i++)
64  {
65  for (int j = 0; j < src.size[_Y]; j++)
66  {
67  dst.mat[i][j] = sqrt(src.mat[i][j]._Val[_RE] * src.mat[i][j]._Val[_RE] + src.mat[i][j]._Val[_IM] * src.mat[i][j]._Val[_IM]);
68  }
69  }
70 }

◆ absMat() [2/4]

template<typename T >
void ophSig::absMat ( matrix< Complex< T >> &  src,
matrix< T > &  dst 
)
inlineprotectedinherited

Function for extracts Complex magnitude value.

Parameters
srcinput signal
dstoutput signal

◆ absMat() [3/4]

template<typename T >
void ophSig::absMat ( matrix< T > &  src,
matrix< T > &  dst 
)
inlineprotectedinherited

Function for extracts real absolute value.

Parameters
srcinput signal
dstoutput signal

Definition at line 74 of file ophSig.cpp.

74  {
75  if (src.size != dst.size) {
76  dst.resize(src.size[_X], src.size[_Y]);
77  }
78  for (int i = 0; i < src.size[_X]; i++)
79  {
80  for (int j = 0; j < src.size[_Y]; j++)
81  {
82  dst.mat[i][j] = abs(src.mat[i][j]);
83  }
84  }
85 }

◆ absMat() [4/4]

template<typename T >
void ophSig::absMat ( matrix< T > &  src,
matrix< T > &  dst 
)
inlineprotectedinherited

Function for extracts real absolute value.

Parameters
srcinput signal
dstoutput signal

◆ addRef() [1/2]

unsigned long Base::addRef ( void  )
inlineinherited

If referenced this(Base's child, not abstract class) instance, must call this method.

Definition at line 75 of file openholo/src/Base.h.

75 { return ++refCnt; }

◆ addRef() [2/2]

unsigned long Base::addRef ( void  )
inlineinherited

If referenced this(Base's child, not abstract class) instance, must call this method.

Definition at line 75 of file Reference/include/Base.h.

75 { return ++refCnt; }

◆ addWaveLengthNComplexFieldDataOHC() [1/2]

void Openholo::addWaveLengthNComplexFieldDataOHC ( const Real  wavelength,
const OphComplexField &  complex_field 
)
inlineprotectedinherited

Function to add ComplexField when adding wavelength data.

Definition at line 297 of file Reference/include/Openholo.h.

298  { OHC_encoder->addWavelengthNComplexFieldData(wavelength, complex_field); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ addWaveLengthNComplexFieldDataOHC() [2/2]

void Openholo::addWaveLengthNComplexFieldDataOHC ( const Real  wavelength,
const OphComplexField &  complex_field 
)
inlineprotectedinherited

Function to add ComplexField when adding wavelength data.

Definition at line 297 of file openholo/src/Openholo.h.

298  { OHC_encoder->addWavelengthNComplexFieldData(wavelength, complex_field); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ angleMat() [1/2]

template<typename T >
void ophSig::angleMat ( matrix< Complex< T >> &  src,
matrix< T > &  dst 
)
inlineprotectedinherited

Function for extracts Complex phase value.

Parameters
srcinput signal
dstoutput signal

Definition at line 88 of file ophSig.cpp.

88  {
89  if (src.size != dst.size) {
90  dst.resize(src.size[_X], src.size[_Y]);
91  }
92  for (int i = 0; i < src.size[_X]; i++)
93  {
94  for (int j = 0; j < src.size[_Y]; j++)
95  {
96  angle(src(i, j), dst(i, j));
97  }
98  }
99 }

◆ angleMat() [2/2]

template<typename T >
void ophSig::angleMat ( matrix< Complex< T >> &  src,
matrix< T > &  dst 
)
inlineprotectedinherited

Function for extracts Complex phase value.

Parameters
srcinput signal
dstoutput signal

◆ checkExtension() [1/2]

int Openholo::checkExtension ( const char *  fname,
const char *  ext 
)
protectedinherited

Functions for extension checking.

Parameters
constchar* File name
constchar* File extension
Returns
int return 0 : The extension of "fname" and "ext" is the same return 1 : The extension of "fname" and "ext" is not the same

Definition at line 79 of file Openholo.cpp.

80 {
81  //return 1 : the extension of "fname" and "ext" is the same
82  // 0 : the extension of "fname" and "ext" is not the same
83 
84  std::string filename(fname);
85  size_t pos = filename.find(ext);
86  if (pos == std::string::npos)
87  //when there is no search string
88  return 0;
89  else
90  return 1;
91 }

◆ checkExtension() [2/2]

int Openholo::checkExtension ( const char *  fname,
const char *  ext 
)
protectedinherited

Functions for extension checking.

Parameters
constchar* File name
constchar* File extension
Returns
int return 0 : The extension of "fname" and "ext" is the same return 1 : The extension of "fname" and "ext" is not the same

◆ conjMat() [1/2]

template<typename T >
void ophSig::conjMat ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst 
)
inlineprotectedinherited

Function for extracts Complex conjugate value.

Parameters
srcinput signal
dstoutput signal

Definition at line 102 of file ophSig.cpp.

102  {
103  if (src.size != dst.size) {
104  dst.resize(src.size[_X], src.size[_Y]);
105  }
106  for (int i = 0; i < src.size[_X]; i++)
107  {
108  for (int j = 0; j < src.size[_Y]; j++)
109  {
110  dst(i, j) = src(i, j).conj();
111 
112  }
113  }
114 }

◆ conjMat() [2/2]

template<typename T >
void ophSig::conjMat ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst 
)
inlineprotectedinherited

Function for extracts Complex conjugate value.

Parameters
srcinput signal
dstoutput signal

◆ convertToFormatGray8() [1/2]

void Openholo::convertToFormatGray8 ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  bytesperpixel 
)
protectedinherited

Function for convert image format to gray8.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intImage size, width
intImage size, Height
intBytes per pixel

Definition at line 310 of file Openholo.cpp.

311 {
312  int idx = 0;
313  unsigned int r = 0, g = 0, b = 0;
314  for (int i = 0; i < w*h*bytesperpixel; i++)
315  {
316  unsigned int r = src[i + 0];
317  unsigned int g = src[i + 1];
318  unsigned int b = src[i + 2];
319  dst[idx++] = (r + g + b) / 3;
320  i += bytesperpixel - 1;
321  }
322 }

◆ convertToFormatGray8() [2/2]

void Openholo::convertToFormatGray8 ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  bytesperpixel 
)
protectedinherited

Function for convert image format to gray8.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intImage size, width
intImage size, Height
intBytes per pixel

◆ expMat() [1/4]

template<typename T >
void ophSig::expMat ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst 
)
inlineprotectedinherited

Function for returns exponent ex.

Parameters
srcinput signal
dstoutput signal

Definition at line 117 of file ophSig.cpp.

117  {
118  if (src.size != dst.size) {
119  dst.resize(src.size[_X], src.size[_Y]);
120  }
121  for (int i = 0; i < src.size[_X]; i++)
122  {
123  for (int j = 0; j < src.size[_Y]; j++)
124  {
125  dst.mat[i][j]._Val[_RE] = exp(src.mat[i][j]._Val[_RE]) * cos(src.mat[i][j]._Val[_IM]);
126  dst.mat[i][j]._Val[_IM] = exp(src.mat[i][j]._Val[_RE]) * sin(src.mat[i][j]._Val[_IM]);
127  }
128  }
129 }

◆ expMat() [2/4]

template<typename T >
void ophSig::expMat ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst 
)
inlineprotectedinherited

Function for returns exponent ex.

Parameters
srcinput signal
dstoutput signal

◆ expMat() [3/4]

template<typename T >
void ophSig::expMat ( matrix< T > &  src,
matrix< T > &  dst 
)
inlineprotectedinherited

Function for returns exponent e(x), where x is complex number.

Parameters
srcinput signal
dstoutput signal

Definition at line 132 of file ophSig.cpp.

132  {
133  if (src.size != dst.size) {
134  dst.resize(src.size[_X], src.size[_Y]);
135  }
136  for (int i = 0; i < src.size[_X]; i++)
137  {
138  for (int j = 0; j < src.size[_Y]; j++)
139  {
140  dst.mat[i][j] = exp(src.mat[i][j]);
141  }
142  }
143 }

◆ expMat() [4/4]

template<typename T >
void ophSig::expMat ( matrix< T > &  src,
matrix< T > &  dst 
)
inlineprotectedinherited

Function for returns exponent e(x), where x is complex number.

Parameters
srcinput signal
dstoutput signal

◆ fft1() [1/3]

void Openholo::fft1 ( int  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 1-dimension operations inside Openholo.

Parameters
intNumber of data
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

Definition at line 324 of file Openholo.cpp.

325 {
326  pnx = n;
327  bool bIn = true;
328 
329  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * n);
330  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * n);
331 
332  if (!in){
333  in = new Complex<Real>[pnx];
334  bIn = false;
335  }
336 
337  for (int i = 0; i < n; i++) {
338  fft_in[i][_RE] = in[i].real();
339  fft_in[i][_IM] = in[i].imag();
340  }
341 
342  fft_sign = sign;
343 
344  if (!bIn) delete[] in;
345 
346  if (sign == OPH_FORWARD)
347  plan_fwd = fftw_plan_dft_1d(n, fft_in, fft_out, sign, flag);
348  else if (sign == OPH_BACKWARD)
349  plan_bwd = fftw_plan_dft_1d(n, fft_in, fft_out, sign, flag);
350  else {
351  LOG("failed fftw : wrong sign");
352  fftFree();
353  return;
354  }
355 }

◆ fft1() [2/3]

template<typename T >
void ophSig::fft1 ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Function for Fast Fourier transform 1D.

Parameters
srcinput signal
dstoutput signal
signsign = OPH_FORWARD is fft and sign= OPH_BACKWARD is inverse fft
flagflag = OPH_ESTIMATE is fine best way to compute the transform but it is need some time, flag = OPH_ESTIMATE is probably sub-optimal

◆ fft1() [3/3]

template<typename T >
void ophSig::fft1 ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Function for Fast Fourier transform 1D.

Parameters
srcinput signal
dstoutput signal
signsign = OPH_FORWARD is fft and sign= OPH_BACKWARD is inverse fft
flagflag = OPH_ESTIMATE is fine best way to compute the transform but it is need some time, flag = OPH_ESTIMATE is probably sub-optimal

Definition at line 190 of file ophSig.cpp.

191 {
192  if (src.size != dst.size) {
193  dst.resize(src.size[_X], src.size[_Y]);
194  }
195  fftw_complex *fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * src.size[_Y]);
196  fftw_complex *fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * src.size[_Y]);
197 
198  for (int i = 0; i < src.size[_Y]; i++) {
199  fft_in[i][_RE] = src(0, i).real();
200  fft_in[i][_IM] = src(0, i).imag();
201  }
202 
203  fftw_plan plan = fftw_plan_dft_1d(src.size[_Y], fft_in, fft_out, sign, flag);
204 
205  fftw_execute(plan);
206  if (sign == OPH_FORWARD)
207  {
208  for (int i = 0; i < src.size[_Y]; i++) {
209  dst(0, i)._Val[_RE] = fft_out[i][_RE];
210  dst(0, i)._Val[_IM] = fft_out[i][_IM];
211  }
212  }
213  else if (sign == OPH_BACKWARD)
214  {
215  for (int i = 0; i < src.size[_Y]; i++) {
216  dst(0, i)._Val[_RE] = fft_out[i][_RE] / src.size[_Y];
217  dst(0, i)._Val[_IM] = fft_out[i][_IM] / src.size[_Y];
218  }
219  }
220 
221  fftw_destroy_plan(plan);
222  fftw_free(fft_in);
223  fftw_free(fft_out);
224 }

◆ fft2() [1/3]

void Openholo::fft2 ( oph::ivec2  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 2-dimension operations inside Openholo.

Parameters
oph::ivec2Number of data(int x, int y)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

Definition at line 357 of file Openholo.cpp.

358 {
359  pnx = n[_X], pny = n[_Y];
360  bool bIn = true;
361 
362  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny);
363  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny);
364 
365  if (!in) {
366  in = new Complex<Real>[pnx * pny];
367  bIn = false;
368  }
369 
370  for (int i = 0; i < pnx * pny; i++) {
371  fft_in[i][_RE] = in[i].real();
372  fft_in[i][_IM] = in[i].imag();
373  }
374 
375  fft_sign = sign;
376 
377  if (!bIn) delete[] in;
378 
379  if (sign == OPH_FORWARD)
380  plan_fwd = fftw_plan_dft_2d(pny, pnx, fft_in, fft_out, sign, flag);
381  else if (sign == OPH_BACKWARD)
382  plan_bwd = fftw_plan_dft_2d(pny, pnx, fft_in, fft_out, sign, flag);
383  else {
384  LOG("failed fftw : wrong sign");
385  fftFree();
386  return;
387  }
388 }

◆ fft2() [2/3]

template<typename T >
void ophSig::fft2 ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Function for Fast Fourier transform 2D.

Parameters
srcinput signal
dstoutput signal
signsign = OPH_FORWARD is fft and sign= OPH_BACKWARD is inverse fft
flagflag = OPH_ESTIMATE is fine best way to compute the transform but it is need some time, flag = OPH_ESTIMATE is probably sub-optimal

Definition at line 226 of file ophSig.cpp.

227 {
228  if (src.size != dst.size) {
229  dst.resize(src.size[_X], src.size[_Y]);
230  }
231 
232  fftw_complex *fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * src.size[_X] * src.size[_Y]);
233  fftw_complex *fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * src.size[_X] * src.size[_Y]);
234 
235  for (int i = 0; i < src.size[_X]; i++) {
236  for (int j = 0; j < src.size[_Y]; j++) {
237  fft_in[src.size[_Y] * i + j][_RE] = src(i, j).real();
238  fft_in[src.size[_Y] * i + j][_IM] = src(i, j).imag();
239  }
240  }
241 
242  fftw_plan plan = fftw_plan_dft_2d(src.size[_X], src.size[_Y], fft_in, fft_out, sign, flag);
243 
244  fftw_execute(plan);
245  if (sign == OPH_FORWARD)
246  {
247  for (int i = 0; i < src.size[_X]; i++) {
248  for (int j = 0; j < src.size[_Y]; j++) {
249  dst(i, j)._Val[_RE] = fft_out[src.size[_Y] * i + j][_RE];
250  dst(i, j)._Val[_IM] = fft_out[src.size[_Y] * i + j][_IM];
251  }
252  }
253  }
254  else if (sign == OPH_BACKWARD)
255  {
256  for (int i = 0; i < src.size[_X]; i++) {
257  for (int j = 0; j < src.size[_Y]; j++) {
258  dst(i, j)._Val[_RE] = fft_out[src.size[_Y] * i + j][_RE] / (src.size[_X] * src.size[_Y]);
259  dst(i, j)._Val[_IM] = fft_out[src.size[_Y] * i + j][_IM] / (src.size[_X] * src.size[_Y]);
260 
261  }
262  }
263  }
264 
265  fftw_destroy_plan(plan);
266  fftw_free(fft_in);
267  fftw_free(fft_out);
268 }

◆ fft2() [3/3]

template<typename T >
void ophSig::fft2 ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Function for Fast Fourier transform 2D.

Parameters
srcinput signal
dstoutput signal
signsign = OPH_FORWARD is fft and sign= OPH_BACKWARD is inverse fft
flagflag = OPH_ESTIMATE is fine best way to compute the transform but it is need some time, flag = OPH_ESTIMATE is probably sub-optimal

◆ fft3() [1/2]

void Openholo::fft3 ( oph::ivec3  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 3-dimension operations inside Openholo.

Parameters
oph::ivec3Number of data(int x, int y, int z)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

Definition at line 390 of file Openholo.cpp.

391 {
392  pnx = n[_X], pny = n[_Y], pnz = n[_Z];
393  bool bIn = true;
394 
395  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny * pnz);
396  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny * pnz);
397 
398  if (!in) {
399  in = new Complex<Real>[pnx * pny * pnz];
400  bIn = false;
401  }
402 
403  for (int i = 0; i < pnx * pny * pnz; i++) {
404  fft_in[i][_RE] = in[i].real();
405  fft_in[i][_IM] = in[i].imag();
406  }
407 
408  fft_sign = sign;
409 
410  if (!bIn) delete[] in;
411 
412  if (sign == OPH_FORWARD)
413  plan_fwd = fftw_plan_dft_3d(pnz, pny, pnx, fft_in, fft_out, sign, flag);
414  else if (sign == OPH_BACKWARD)
415  plan_bwd = fftw_plan_dft_3d(pnz, pny, pnx, fft_in, fft_out, sign, flag);
416  else {
417  LOG("failed fftw : wrong sign");
418  fftFree();
419  return;
420  }
421 }

◆ fft3() [2/2]

void Openholo::fft3 ( oph::ivec3  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protectedinherited

Functions for performing fftw 3-dimension operations inside Openholo.

Parameters
oph::ivec3Number of data(int x, int y, int z)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

◆ fftExecute() [1/2]

void Openholo::fftExecute ( Complex< Real > *  out)
protectedinherited

Execution functions to be called after fft1, fft2, and fft3.

Parameters
Complex<Real>*Dest of data

Definition at line 423 of file Openholo.cpp.

424 {
425  if (fft_sign == OPH_FORWARD)
426  fftw_execute(plan_fwd);
427  else if (fft_sign == OPH_BACKWARD)
428  fftw_execute(plan_bwd);
429  else {
430  LOG("failed fftw : wrong sign");
431  out = nullptr;
432  fftFree();
433  return;
434  }
435 
436  for (int i = 0; i < pnx * pny * pnz; i++) {
437  out[i][_RE] = fft_out[i][_RE];
438  out[i][_IM] = fft_out[i][_IM];
439  }
440 
441  fftFree();
442 }

◆ fftExecute() [2/2]

void Openholo::fftExecute ( Complex< Real > *  out)
protectedinherited

Execution functions to be called after fft1, fft2, and fft3.

Parameters
Complex<Real>*Dest of data

◆ fftShift() [1/3]

void Openholo::fftShift ( int  nx,
int  ny,
Complex< Real > *  input,
Complex< Real > *  output 
)
protectedinherited

Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom-left.

Parameters
intthe number of column of the input data
intthe number of row of the input data
Complex<Real>*input data variable
Complex<Real>*output data variable

Definition at line 511 of file Openholo.cpp.

512 {
513  for (int i = 0; i < nx; i++)
514  {
515  for (int j = 0; j < ny; j++)
516  {
517  int ti = i - nx / 2; if (ti < 0) ti += nx;
518  int tj = j - ny / 2; if (tj < 0) tj += ny;
519 
520  output[ti + tj * nx] = input[i + j * nx];
521  }
522  }
523 }

◆ fftShift() [2/3]

template<typename T >
void ophSig::fftShift ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst 
)
protectedinherited

Function for Shift zero-frequency component to center of spectrum.

Parameters
srcinput signal
dstoutput signal

Definition at line 703 of file ophsig/src/ophSig.h.

704 {
705  if (src.size != dst.size) {
706  dst.resize(src.size[_X], src.size[_Y]);
707  }
708  int xshift = src.size[_X] / 2;
709  int yshift = src.size[_Y] / 2;
710  for (int i = 0; i < src.size[_X]; i++)
711  {
712  int ii = (i + xshift) % src.size[_X];
713  for (int j = 0; j < src.size[_Y]; j++)
714  {
715  int jj = (j + yshift) % src.size[_Y];
716  dst.mat[ii][jj]._Val[_RE] = src.mat[i][j].real();
717  dst.mat[ii][jj]._Val[_IM] = src.mat[i][j].imag();
718  }
719  }
720 }

◆ fftShift() [3/3]

template<typename T >
void ophSig::fftShift ( matrix< Complex< T >> &  src,
matrix< Complex< T >> &  dst 
)
protectedinherited

Function for Shift zero-frequency component to center of spectrum.

Parameters
srcinput signal
dstoutput signal

◆ fftwShift() [1/2]

void Openholo::fftwShift ( Complex< Real > *  src,
Complex< Real > *  dst,
int  nx,
int  ny,
int  type,
bool  bNormalized = false 
)
protectedinherited

Convert data from the spatial domain to the frequency domain using 2D FFT on CPU.

Parameters
Complex<Real>*Input data variable
Complex<Real>*Output data variable
intthe number of column of the input data
intthe number of row of the input data
intIf type == 1, forward FFT, if type == -1, backward FFT.
boolIf bNomarlized == true, normalize the result after FFT.

Definition at line 466 of file Openholo.cpp.

467 {
468  Complex<Real>* tmp = new Complex<Real>[nx*ny];
469  memset(tmp, 0, sizeof(Complex<Real>)*nx*ny);
470  fftShift(nx, ny, src, tmp);
471 
472  fftw_complex *in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);
473  fftw_complex *out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);
474 
475  for (int i = 0; i < nx*ny; i++) {
476  in[i][_RE] = tmp[i][_RE];
477  in[i][_IM] = tmp[i][_IM];
478  }
479 
480  fftw_plan plan = nullptr;
481  if (!plan_fwd && !plan_bwd) {
482  plan = fftw_plan_dft_2d(ny, nx, in, out, type, OPH_ESTIMATE);
483  fftw_execute(plan);
484  }
485  else {
486  if (type == OPH_FORWARD)
487  fftw_execute_dft(plan_fwd, in, out);
488  else if (type == OPH_BACKWARD)
489  fftw_execute_dft(plan_bwd, in, out);
490  }
491 
492  int normalF = 1;
493  if (bNormalized) normalF = nx * ny;
494  memset(tmp, 0, sizeof(Complex<Real>)*nx*ny);
495 
496  for (int k = 0; k < nx*ny; k++) {
497  tmp[k][_RE] = out[k][_RE] / normalF;
498  tmp[k][_IM] = out[k][_IM] / normalF;
499  }
500 
501  fftw_free(in);
502  fftw_free(out);
503  if (plan)
504  fftw_destroy_plan(plan);
505 
506  memset(dst, 0, sizeof(Complex<Real>)*nx*ny);
507  fftShift(nx, ny, tmp, dst);
508  delete[] tmp;
509 }
void fftShift(int nx, int ny, Complex< Real > *input, Complex< Real > *output)
Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom...
Definition: Openholo.cpp:511

◆ fftwShift() [2/2]

void Openholo::fftwShift ( Complex< Real > *  src,
Complex< Real > *  dst,
int  nx,
int  ny,
int  type,
bool  bNormalized = false 
)
protectedinherited

Convert data from the spatial domain to the frequency domain using 2D FFT on CPU.

Parameters
Complex<Real>*Input data variable
Complex<Real>*Output data variable
intthe number of column of the input data
intthe number of row of the input data
intIf type == 1, forward FFT, if type == -1, backward FFT.
boolIf bNomarlized == true, normalize the result after FFT.

◆ getComplexHFromPSDH()

bool ophSig::getComplexHFromPSDH ( const char *  fname0,
const char *  fname90,
const char *  fname180,
const char *  fname270 
)
inherited

Extraction of complex field from 4 phase shifted interference patterns .

Parameters
fname0,fname90,fname180,fname270Input image files for 4 interference patterns
Returns
if works well return 0 or error occurs return -1

◆ getImgSize() [1/2]

int Openholo::getImgSize ( int &  w,
int &  h,
int &  bytesperpixel,
const char *  file_name 
)
protectedinherited

Function for getting the image size.

Parameters
int&Image size - width
int&Image size - Height
int&Bytes per pixel
constchar* Input file name

Definition at line 259 of file Openholo.cpp.

260 {
261  char bmpFile[256];
262  sprintf_s(bmpFile, "%s", file_name);
263  FILE *infile;
264  fopen_s(&infile, bmpFile, "rb");
265  if (infile == NULL) { LOG("No Image File"); return 0; }
266 
267  // BMP Header Information
268  fileheader hf;
269  bitmapinfoheader hInfo;
270  fread(&hf, sizeof(fileheader), 1, infile);
271  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return 0;
272  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
273  //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; }
274 
275  w = hInfo.width;
276  h = hInfo.height;
277  bytesperpixel = hInfo.bitsperpixel / 8;
278 
279  fclose(infile);
280 
281  return 1;
282 }

◆ getImgSize() [2/2]

int Openholo::getImgSize ( int &  w,
int &  h,
int &  bytesperpixel,
const char *  file_name 
)
protectedinherited

Function for getting the image size.

Parameters
int&Image size - width
int&Image size - Height
int&Bytes per pixel
constchar* Input file name

◆ imgScaleBilnear() [1/2]

void Openholo::imgScaleBilnear ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  neww,
int  newh 
)
protectedinherited

Function for change image size.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intOriginal width
intOriginal height
intWidth to replace
intHeight to replace

◆ imgScaleBilnear() [2/2]

void Openholo::imgScaleBilnear ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  neww,
int  newh 
)
protectedinherited

Function for change image size.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intOriginal width
intOriginal height
intWidth to replace
intHeight to replace

Definition at line 284 of file Openholo.cpp.

285 {
286  for (int y = 0; y < newh; y++)
287  {
288  for (int x = 0; x < neww; x++)
289  {
290  float gx = (x / (float)neww) * (w - 1);
291  float gy = (y / (float)newh) * (h - 1);
292 
293  int gxi = (int)gx;
294  int gyi = (int)gy;
295 
296  uint32_t a00 = src[gxi + 0 + gyi * w];
297  uint32_t a01 = src[gxi + 1 + gyi * w];
298  uint32_t a10 = src[gxi + 0 + (gyi + 1)*w];
299  uint32_t a11 = src[gxi + 1 + (gyi + 1)*w];
300 
301  float dx = gx - gxi;
302  float dy = gy - gyi;
303 
304  dst[x + y * neww] = int(a00 * (1 - dx)*(1 - dy) + a01 * dx*(1 - dy) + a10 * (1 - dx)*dy + a11 * dx*dy);
305 
306  }
307  }
308 }

◆ linInterp() [1/2]

template<typename T >
void ophSig::linInterp ( vector< T > &  X,
matrix< Complex< T >> &  in,
vector< T > &  Xq,
matrix< Complex< T >> &  out 
)
protectedinherited

Function for Linear interpolation 1D.

Parameters
Xinput signal coordinate
ininput signal
Xqoutput signal coordinate
outoutput signal

◆ linInterp() [2/2]

template<typename T >
void ophSig::linInterp ( vector< T > &  X,
matrix< Complex< T >> &  in,
vector< T > &  Xq,
matrix< Complex< T >> &  out 
)
protectedinherited

Function for Linear interpolation 1D.

Parameters
Xinput signal coordinate
ininput signal
Xqoutput signal coordinate
outoutput signal

Definition at line 295 of file ophSig.cpp.

296 {
297  if (src.size != dst.size) {
298  dst.resize(src.size[_X], src.size[_Y]);
299  }
300  int size = src.size[_Y];
301 
302  for (int i = 0, j = 0; j < dst.size[_Y]; j++)
303  {
304  if ((Xq[j]) >= (X[size - 2]))
305  {
306  i = size - 2;
307  }
308  else
309  {
310  while ((Xq[j]) >(X[i + 1])) i++;
311  }
312  dst(0, j)._Val[_RE] = src(0, i).real() + (src(0, i + 1).real() - src(0, i).real()) / (X[i + 1] - X[i]) * (Xq[j] - X[i]);
313  dst(0, j)._Val[_IM] = src(0, i).imag() + (src(0, i + 1).imag() - src(0, i).imag()) / (X[i + 1] - X[i]) * (Xq[j] - X[i]);
314  }
315 }

◆ linspace() [1/2]

vector< Real > ophSig::linspace ( double  first,
double  last,
int  len 
)
protectedinherited

Generate linearly spaced vector.

Parameters
firstfirst number of vector
lastlast number of vector
lenvector with specified number of values
Returns
result vector

Definition at line 272 of file ophSig.cpp.

272  {
273  vector<Real> result(len);
274 
275  double step = (last - first) / (len - 1);
276  for (int i = 0; i < len; i++) { result[i] = first + i*step; }
277  return result;
278 }

◆ linspace() [2/2]

vector<Real> ophSig::linspace ( double  first,
double  last,
int  len 
)
protectedinherited

Generate linearly spaced vector.

Parameters
firstfirst number of vector
lastlast number of vector
lenvector with specified number of values
Returns
result vector

◆ load() [1/2]

bool ophSig::load ( const char *  real,
const char *  imag 
)
inherited

Load bmp or bin file.

Parameters
realreal data file name
imagimag data file name
bitpixelbit per pixel
Returns
if works well return 0 or error occurs return -1

Definition at line 370 of file ophSig.cpp.

371 {
372  string realname = real;
373  string imagname = imag;
374 
375  char* RGB_name[3] = { "","","" };
376 
377  if (_wavelength_num > 1) {
378  RGB_name[0] = "_B";
379  RGB_name[1] = "_G";
380  RGB_name[2] = "_R";
381  }
382 
383  int checktype = static_cast<int>(realname.rfind("."));
384 
385  OphRealField* realMat = new OphRealField[_wavelength_num];
386  OphRealField* imagMat = new OphRealField[_wavelength_num];
387 
388  std::string realtype = realname.substr(checktype + 1, realname.size());
389  std::string imgtype = imagname.substr(checktype + 1, realname.size());
390 
391  ComplexH = new OphComplexField[_wavelength_num];
392 
393  if (realtype != imgtype) {
394  LOG("failed : The data type between real and imaginary is different!\n");
395  return false;
396  }
397  if (realtype == "bmp")
398  {
399  realname = real;
400  imagname = imag;
401 
402  uchar* realdata = loadAsImg(realname.c_str());
403  uchar* imagdata = loadAsImg(imagname.c_str());
404 
405  if (realdata == 0 && imagdata == 0) {
406  cout << "failed : hologram data load was failed." << endl;
407  return false;
408  }
409 
410  for (int z = 0; z < _wavelength_num; z++)
411  {
412  realMat[z].resize(context_.pixel_number[_X], context_.pixel_number[_Y]);
413  imagMat[z].resize(context_.pixel_number[_X], context_.pixel_number[_Y]);
414  for (int i = context_.pixel_number[_X] - 1; i >= 0; i--)
415  {
416  for (int j = 0; j < context_.pixel_number[_Y]; j++)
417  {
418  realMat[z](context_.pixel_number[_X] - i - 1, j) = (double)realdata[(i * context_.pixel_number[_Y] + j)*_wavelength_num + z];
419  imagMat[z](context_.pixel_number[_X] - i - 1, j) = (double)imagdata[(i * context_.pixel_number[_Y] + j)*_wavelength_num + z];
420  }
421  }
422  }
423  delete[] realdata;
424  delete[] imagdata;
425  }
426  else if (realtype == "bin")
427  {
428  double *realdata = new double[context_.pixel_number[_X] * context_.pixel_number[_Y]];
429  double *imagdata = new double[context_.pixel_number[_X] * context_.pixel_number[_Y]];
430 
431  for (int z = 0; z < _wavelength_num; z++)
432  {
433  realname = real;
434  imagname = imag;
435 
436  realname.insert(checktype, RGB_name[z]);
437  imagname.insert(checktype, RGB_name[z]);
438 
439  ifstream freal(realname.c_str(), ifstream::binary);
440  ifstream fimag(imagname.c_str(), ifstream::binary);
441 
442  freal.read(reinterpret_cast<char*>(realdata), sizeof(double) * context_.pixel_number[_X] * context_.pixel_number[_Y]);
443  fimag.read(reinterpret_cast<char*>(imagdata), sizeof(double) * context_.pixel_number[_X] * context_.pixel_number[_Y]);
444 
445  realMat[z].resize(context_.pixel_number[_X], context_.pixel_number[_Y]);
446  imagMat[z].resize(context_.pixel_number[_X], context_.pixel_number[_Y]);
447 
448  for (int i = 0; i < context_.pixel_number[_X]; i++)
449  {
450  for (int j = 0; j < context_.pixel_number[_Y]; j++)
451  {
452  realMat[z](i, j) = realdata[i + j * context_.pixel_number[_X]];
453  imagMat[z](i, j) = imagdata[i + j * context_.pixel_number[_X]];
454  }
455  }
456  freal.close();
457  fimag.close();
458  }
459  delete[] realdata;
460  delete[] imagdata;
461  }
462  else
463  {
464  LOG("Error: wrong type\n");
465  }
466  //nomalization
467  double realout, imagout;
468  for (int z = 0; z < _wavelength_num; z++)
469  {
470  meanOfMat(realMat[z], realout); meanOfMat(imagMat[z], imagout);
471  realMat[z] / realout; imagMat[z] / imagout;
472  absMat(realMat[z], realMat[z]);
473  absMat(imagMat[z], imagMat[z]);
474  realout = maxOfMat(realMat[z]); imagout = maxOfMat(imagMat[z]);
475  realMat[z] / realout; imagMat[z] / imagout;
476  realout = minOfMat(realMat[z]); imagout = minOfMat(imagMat[z]);
477  realMat[z] - realout; imagMat[z] - imagout;
478 
479  ComplexH[z].resize(context_.pixel_number[_X], context_.pixel_number[_Y]);
480 
481  for (int i = 0; i < context_.pixel_number[_X]; i++)
482  {
483  for (int j = 0; j < context_.pixel_number[_Y]; j++)
484  {
485  ComplexH[z](i, j)._Val[_RE] = realMat[z](i, j);
486  ComplexH[z](i, j)._Val[_IM] = imagMat[z](i, j);
487  }
488  }
489  }
490  LOG("Reading Openholo Complex Field File...%s, %s", realname.c_str(), imagname.c_str());
491 
492  return true;
493 }
Real maxOfMat(matrix< T > &src)
Function for extracts max of matrix.
Definition: ophSig.cpp:146
void meanOfMat(matrix< T > &input, double &output)
Function for returns exponent e(x), where x is real number.
Definition: ophSig.cpp:281
void absMat(matrix< Complex< T >> &src, matrix< T > &dst)
Function for extracts Complex magnitude value.
Definition: ophSig.cpp:59
virtual uchar * loadAsImg(const char *fname)
Function for loading image files.
Definition: Openholo.cpp:146
Real minOfMat(matrix< T > &src)
Function for extracts min of matrix.
Definition: ophSig.cpp:177

◆ load() [2/2]

bool ophSig::load ( const char *  real,
const char *  imag 
)
inherited

Load bmp or bin file.

Parameters
realreal data file name
imagimag data file name
bitpixelbit per pixel
Returns
if works well return 0 or error occurs return -1

◆ loadAsImg() [1/2]

uchar * Openholo::loadAsImg ( const char *  fname)
virtualinherited

Function for loading image files.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

Definition at line 146 of file Openholo.cpp.

147 {
148  FILE *infile;
149  fopen_s(&infile, fname, "rb");
150  if (infile == nullptr) { LOG("No such file"); return 0; }
151 
152  // BMP Header Information
153  fileheader hf;
154  bitmapinfoheader hInfo;
155  fread(&hf, sizeof(fileheader), 1, infile);
156  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') { LOG("Not BMP File"); return 0; }
157 
158  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
159  fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET);
160 
161  oph::uchar *img_tmp;
162  if (hInfo.imagesize == 0) {
163  img_tmp = new uchar[hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)];
164  fread(img_tmp, sizeof(oph::uchar), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile);
165  }
166  else {
167  img_tmp = new uchar[hInfo.imagesize];
168  fread(img_tmp, sizeof(oph::uchar), hInfo.imagesize, infile);
169  }
170  fclose(infile);
171 
172  return img_tmp;
173 }

◆ loadAsImg() [2/2]

virtual uchar* Openholo::loadAsImg ( const char *  fname)
virtualinherited

Function for loading image files.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

◆ loadAsImgUpSideDown() [1/2]

int Openholo::loadAsImgUpSideDown ( const char *  fname,
uchar *  dst 
)
protectedinherited

Function for loading image files | Output image data upside down.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

Definition at line 218 of file Openholo.cpp.

219 {
220  FILE *infile;
221  fopen_s(&infile, fname, "rb");
222  if (infile == nullptr) { LOG("No such file"); return 0; }
223 
224  // BMP Header Information
225  fileheader hf;
226  bitmapinfoheader hInfo;
227  fread(&hf, sizeof(fileheader), 1, infile);
228  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') { LOG("Not BMP File"); return 0; }
229 
230  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
231  fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET);
232 
233  oph::uchar* img_tmp;
234  if (hInfo.imagesize == 0) {
235  img_tmp = new oph::uchar[hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)];
236  fread(img_tmp, sizeof(oph::uchar), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile);
237  }
238  else {
239  img_tmp = new oph::uchar[hInfo.imagesize];
240  fread(img_tmp, sizeof(oph::uchar), hInfo.imagesize, infile);
241  }
242  fclose(infile);
243 
244  // data upside down
245  int bytesperpixel = hInfo.bitsperpixel / 8;
246  int rowsz = bytesperpixel * hInfo.width;
247 
248  for (oph::uint k = 0; k < hInfo.height*rowsz; k++) {
249  int r = k / rowsz;
250  int c = k % rowsz;
251  ((oph::uchar*)dst)[(hInfo.height - r - 1)*rowsz + c] = img_tmp[r*rowsz + c];
252  }
253 
254  delete[] img_tmp;
255 
256  return 1;
257 }

◆ loadAsImgUpSideDown() [2/2]

int Openholo::loadAsImgUpSideDown ( const char *  fname,
uchar *  dst 
)
protectedinherited

Function for loading image files | Output image data upside down.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

◆ loadAsOhc() [1/2]

int ophSig::loadAsOhc ( const char *  fname)
virtualinherited

Function to read OHC file.

Reimplemented from Openholo.

Definition at line 317 of file ophSig.cpp.

318 {
319  std::string fullname = fname;
320  if (checkExtension(fname, ".ohc") == 0) fullname.append(".ohc");
321  OHC_decoder->setFileName(fullname.c_str());
322 
323  if (!OHC_decoder->load()) return -1;
324  vector<Real> wavelengthArray;
325  OHC_decoder->getWavelength(wavelengthArray);
326  _wavelength_num = OHC_decoder->getNumOfWavlen();
327  int wavelength_num = OHC_decoder->getNumOfWavlen();
328 
329  context_.pixel_number = OHC_decoder->getNumOfPixel();
330 
331  context_.wave_length = new Real[_wavelength_num];
332 
333  ComplexH = new OphComplexField[_wavelength_num];
334 
335  for (int i = 0; i < _wavelength_num; i++)
336  {
337  context_.wave_length[i] = wavelengthArray[(_wavelength_num - 1) - i];
338 
339  ComplexH[i].resize(context_.pixel_number[_X], context_.pixel_number[_Y]);
340  OHC_decoder->getComplexFieldData(ComplexH[i], (_wavelength_num - 1) - i);
341  }
342  return true;
343 }
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79

◆ loadAsOhc() [2/2]

int ophSig::loadAsOhc ( const char *  fname)
virtualinherited

Function to read OHC file.

Reimplemented from Openholo.

◆ loadPhaseOriginal() [1/2]

bool ophSigPU::loadPhaseOriginal ( const char *  fname,
int  bitpixel 
)

Load original wrapped phase data.

Parameters
fname: image file name of wrapped phase data
bitpixel: the number of bits per pixel in the image file

◆ loadPhaseOriginal() [2/2]

bool ophSigPU::loadPhaseOriginal ( const char *  fname,
int  bitpixel 
)

Load original wrapped phase data.

Parameters
fname: image file name of wrapped phase data
bitpixel: the number of bits per pixel in the image file

Definition at line 13 of file ophSigPU.cpp.

14 {
15  string fnamestr = fname;
16  int checktype = static_cast<int>(fnamestr.rfind("."));
17  matrix<Real> phaseMat;
18 
19  std::string filetype = fnamestr.substr(checktype + 1, fnamestr.size());
20 
21  if (filetype == "bmp")
22  {
23  FILE *fphase;
24  fileheader hf;
25  bitmapinfoheader hInfo;
26  fopen_s(&fphase, fnamestr.c_str(), "rb");
27  if (!fphase)
28  {
29  LOG("real bmp file open fail!\n");
30  return false;
31  }
32  fread(&hf, sizeof(fileheader), 1, fphase);
33  fread(&hInfo, sizeof(bitmapinfoheader), 1, fphase);
34 
35  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') { LOG("Not BMP File!\n"); }
36  if ((hInfo.height == 0) || (hInfo.width == 0))
37  {
38  LOG("bmp header is empty!\n");
39  hInfo.height = _cfgSig.rows;
40  hInfo.width = _cfgSig.cols;
41  if (_cfgSig.rows == 0 || _cfgSig.cols == 0)
42  {
43  LOG("check your parameter file!\n");
44  return false;
45  }
46  }
47  if ((_cfgSig.rows != hInfo.height) || (_cfgSig.cols != hInfo.width)) {
48  LOG("image size is different!\n");
49  _cfgSig.rows = hInfo.height;
50  _cfgSig.cols = hInfo.width;
51  LOG("changed parameter of size %d x %d\n", _cfgSig.cols, _cfgSig.rows);
52  }
53  hInfo.bitsperpixel = bitpixel;
54  if (bitpixel == 8)
55  {
56  rgbquad palette[256];
57  fread(palette, sizeof(rgbquad), 256, fphase);
58 
59  phaseMat.resize(hInfo.height, hInfo.width);
60  }
61  else
62  {
63  LOG("currently only 8 bitpixel is supported.");
64  /*
65  phaseMat[0].resize(hInfo.height, hInfo.width);
66  phaseMat[1].resize(hInfo.height, hInfo.width);
67  phaseMat[2].resize(hInfo.height, hInfo.width); */
68  }
69 
70  uchar* phasedata = (uchar*)malloc(sizeof(uchar)*hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8));
71 
72  fread(phasedata, sizeof(uchar), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), fphase);
73 
74  fclose(fphase);
75 
76  for (int i = hInfo.height - 1; i >= 0; i--)
77  {
78  for (int j = 0; j < static_cast<int>(hInfo.width); j++)
79  {
80  for (int z = 0; z < (hInfo.bitsperpixel / 8); z++)
81  {
82  phaseMat(hInfo.height - i - 1, j) = (double)phasedata[i*hInfo.width*(hInfo.bitsperpixel / 8) + (hInfo.bitsperpixel / 8)*j + z];
83  }
84  }
85  }
86  LOG("file load complete!\n");
87 
88  free(phasedata);
89  }
90  else if (filetype == "bin")
91  {
92  if (bitpixel == 8)
93  {
94 
95  ifstream fphase(fnamestr, ifstream::binary);
96  phaseMat.resize(_cfgSig.rows, _cfgSig.cols);
97  int total = _cfgSig.rows*_cfgSig.cols;
98  double *phasedata = new double[total];
99  int i = 0;
100  fphase.read(reinterpret_cast<char*>(phasedata), sizeof(double) * total);
101 
102  for (int col = 0; col < _cfgSig.cols; col++)
103  {
104  for (int row = 0; row < _cfgSig.rows; row++)
105  {
106  phaseMat(row, col) = phasedata[_cfgSig.rows*col + row];
107  }
108  }
109 
110  fphase.close();
111  delete[]phasedata;
112  }
113  else if (bitpixel == 24)
114  {
115  LOG("currently only 8 bitpixel is supported.");
116  /*
117  phaseMat[0].resize(_cfgSig.rows, _cfgSig.cols);
118  phaseMat[1].resize(_cfgSig.rows, _cfgSig.cols);
119  phaseMat[2].resize(_cfgSig.rows, _cfgSig.cols);
120 
121  int total = _cfgSig.rows*_cfgSig.cols;
122 
123 
124  string RGB_name[] = { "_B","_G","_R" };
125  double *phasedata = new double[total];
126 
127  for (int z = 0; z < (bitpixel / 8); z++)
128  {
129  ifstream fphase(strtok((char*)fnamestr.c_str(), ".") + RGB_name[z] + "bin", ifstream::binary);
130 
131  fphase.read(reinterpret_cast<char*>(phasedata), sizeof(double) * total);
132 
133  for (int col = 0; col < _cfgSig.cols; col++)
134  {
135  for (int row = 0; row < _cfgSig.rows; row++)
136  {
137  phaseMat[z](row, col) = phasedata[_cfgSig.rows*col + row];
138  }
139  }
140  fphase.close();
141  }
142  delete[] phasedata; */
143  }
144  }
145  else
146  {
147  LOG("wrong type\n");
148  }
149 
152  //nomalization
153  Nr = _cfgSig.rows;
154  Nc = _cfgSig.cols;
155  PhaseOriginal.resize(Nr, Nc);
156  PhaseUnwrapped.resize(Nr, Nc);
157  for (int i = 0; i < _cfgSig.rows; i++)
158  {
159  for (int j = 0; j < _cfgSig.cols; j++)
160  {
161  PhaseOriginal(i, j) = phaseMat(i, j) / 255.0*M_PI*2 - M_PI;
162  PhaseUnwrapped(i, j) = 0;
163  }
164  }
165 
166  LOG("data nomalization complete\n");
167 
168  return true;
169 }

◆ maxOfMat() [1/2]

template<typename T >
Real ophSig::maxOfMat ( matrix< T > &  src)
inlineprotectedinherited

Function for extracts max of matrix.

Parameters
srcinput signal

Definition at line 146 of file ophSig.cpp.

146  {
147  Real max = MIN_DOUBLE;
148  for (int i = 0; i < src.size[_X]; i++)
149  {
150  for (int j = 0; j < src.size[_Y]; j++)
151  {
152  if (src(i, j) > max) max = src(i, j);
153  }
154  }
155  return max;
156 }

◆ maxOfMat() [2/2]

template<typename T >
Real ophSig::maxOfMat ( matrix< T > &  src)
inlineprotectedinherited

Function for extracts max of matrix.

Parameters
srcinput signal

◆ meanOfMat() [1/2]

template<typename T >
void ophSig::meanOfMat ( matrix< T > &  input,
double &  output 
)
inlineprotectedinherited

Function for returns exponent e(x), where x is real number.

Parameters
srcinput signal
dstoutput signal

Definition at line 281 of file ophSig.cpp.

282 {
283  dst = 0;
284  for (int i = 0; i < src.size[_X]; i++)
285  {
286  for (int j = 0; j < src.size[_Y]; j++)
287  {
288  dst += src(i, j);
289  }
290  }
291  dst = dst / (src.size[_X] * src.size[_Y]);
292 }

◆ meanOfMat() [2/2]

template<typename T >
void ophSig::meanOfMat ( matrix< T > &  input,
double &  output 
)
inlineprotectedinherited

Function for returns exponent e(x), where x is real number.

Parameters
srcinput signal
dstoutput signal

◆ meshgrid() [1/2]

template<typename T >
void ophSig::meshgrid ( vector< T > &  src1,
vector< T > &  src2,
matrix< T > &  dst1,
matrix< T > &  dst2 
)
protectedinherited

Function for returns 2d matrix based on vector src1, src2.

Parameters
src1input vector
src2input vector
dst1input signal
dst2input signal

Definition at line 159 of file ophSig.cpp.

160 {
161  int src1_total = static_cast<int>(src1.size());
162  int src2_total = static_cast<int>(src2.size());
163 
164  dst1.resize(src2_total, src1_total);
165  dst2.resize(src2_total, src1_total);
166  for (int i = 0; i < src1_total; i++)
167  {
168  for (int j = 0; j < src2_total; j++)
169  {
170  dst1(j, i) = src1.at(i);
171  dst2(j, i) = src2.at(j);
172  }
173  }
174 }

◆ meshgrid() [2/2]

template<typename T >
void ophSig::meshgrid ( vector< T > &  src1,
vector< T > &  src2,
matrix< T > &  dst1,
matrix< T > &  dst2 
)
protectedinherited

Function for returns 2d matrix based on vector src1, src2.

Parameters
src1input vector
src2input vector
dst1input signal
dst2input signal

◆ minOfMat() [1/2]

template<typename T >
Real ophSig::minOfMat ( matrix< T > &  src)
inlineprotectedinherited

Function for extracts min of matrix.

Parameters
srcinput signal

Definition at line 177 of file ophSig.cpp.

177  {
178  Real min = MAX_DOUBLE;
179  for (int i = 0; i < src.size[_X]; i++)
180  {
181  for (int j = 0; j < src.size[_Y]; j++)
182  {
183  if (src(i, j) < min) min = src(i, j);
184  }
185  }
186  return min;
187 }

◆ minOfMat() [2/2]

template<typename T >
Real ophSig::minOfMat ( matrix< T > &  src)
inlineprotectedinherited

Function for extracts min of matrix.

Parameters
srcinput signal

◆ ophFree() [1/2]

void ophSig::ophFree ( void  )
protectedvirtualinherited

Pure virtual function for override in child classes.

Reimplemented from Openholo.

Definition at line 1186 of file ophSig.cpp.

1186  {
1187 
1188 }

◆ ophFree() [2/2]

virtual void ophSig::ophFree ( void  )
protectedvirtualinherited

Pure virtual function for override in child classes.

Reimplemented from Openholo.

◆ propagationHolo() [1/4]

bool ophSig::propagationHolo ( float  depth)
inherited

Function for Chromatic aberration compensation filter.

Returns
if works well return 0 or error occurs return -1

◆ propagationHolo() [2/4]

bool ophSig::propagationHolo ( float  depth)
inherited

Function for Chromatic aberration compensation filter.

Returns
if works well return 0 or error occurs return -1

Definition at line 820 of file ophSig.cpp.

820  {
821  int i, j;
822  Real x, y, sigmaf;
823  int nx = context_.pixel_number[_X];
824  int ny = context_.pixel_number[_Y];
825 
826  OphComplexField FH;
827  OphComplexField FFZP;
828 
829  for (int z = 0; z < _wavelength_num; z++) {
830 
831  sigmaf = (depth * context_.wave_length[z]) / (4 * M_PI);
832 
833  FH.resize(nx, ny);
834  FFZP.resize(nx, ny);
835 
836  fft2(ComplexH[z], FH);
837 
838  for (i = 0; i < nx; i++)
839  {
840  int ii = (i + ny / 2) % ny;
841  for (j = 0; j < ny; j++)
842  {
843  x = (2 * M_PI * (i)) / _width - M_PI*(nx - 1) / (_width);
844  y = (2 * M_PI * (j)) / _height - M_PI*(ny - 1) / (_height);
845  int jj = (j + nx / 2) % nx;
846  double temp = sigmaf * ((x * x + y * y));
847  FFZP(ii, jj)._Val[_RE] = cos(temp) * FH(ii, jj)._Val[_RE] - sin(temp) * FH(ii, jj)._Val[_IM];
848  FFZP(ii, jj)._Val[_IM] = sin(temp) * FH(ii, jj)._Val[_RE] + cos(temp) * FH(ii, jj)._Val[_IM];
849  }
850  }
851 
852  this->fft2(FFZP, ComplexH[z], OPH_BACKWARD);
853  }
854  return true;
855 }
void fft2(matrix< Complex< T >> &src, matrix< Complex< T >> &dst, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Function for Fast Fourier transform 2D.
Definition: ophSig.cpp:226

◆ propagationHolo() [3/4]

OphComplexField ophSig::propagationHolo ( OphComplexField  complexH,
float  depth 
)
inherited

Function for propagation hologram.

Parameters
depthposition from hologram plane to propagation hologram plane
Returns
output signal

Definition at line 857 of file ophSig.cpp.

857  {
858  int i, j;
859  Real x, y, sigmaf;
860 
861  OphComplexField FH;
862  OphComplexField FFZP;
863 
864  int nx = context_.pixel_number[_X];
865  int ny = context_.pixel_number[_Y];
866 
867  sigmaf = (depth * (*context_.wave_length)) / (4 * M_PI);
868 
869  FH.resize(nx, ny);
870  FFZP.resize(nx, ny);
871  fft2(complexH, FH);
872 
873  for (i = 0; i < nx; i++)
874  {
875  int ii = (i + ny / 2) % ny;
876  for (j = 0; j < ny; j++)
877  {
878  x = (2 * M_PI * (i)) / _width - M_PI*(nx - 1) / (_width);
879  y = (2 * M_PI * (j)) / _height - M_PI*(ny - 1) / (_height);
880  int jj = (j + nx / 2) % nx;
881  double temp = sigmaf * ((x * x + y * y));
882  FFZP(ii, jj)._Val[_RE] = cos(temp) * FH(ii, jj)._Val[_RE] - sin(temp) * FH(ii, jj)._Val[_IM];
883  FFZP(ii, jj)._Val[_IM] = sin(temp) * FH(ii, jj)._Val[_RE] + cos(temp) * FH(ii, jj)._Val[_IM];
884  }
885  }
886  fft2(FFZP, complexH, OPH_BACKWARD);
887 
888  return complexH;
889 }
void fft2(matrix< Complex< T >> &src, matrix< Complex< T >> &dst, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Function for Fast Fourier transform 2D.
Definition: ophSig.cpp:226

◆ propagationHolo() [4/4]

OphComplexField ophSig::propagationHolo ( OphComplexField  complexH,
float  depth 
)
inherited

Function for propagation hologram.

Parameters
depthposition from hologram plane to propagation hologram plane
Returns
output signal

◆ readConfig() [1/2]

bool ophSigPU::readConfig ( const char *  fname)
virtual

Read configure file.

Parameters
fname: configure file name

Reimplemented from ophSig.

◆ readConfig() [2/2]

bool ophSigPU::readConfig ( const char *  fname)
virtual

Read configure file.

Parameters
fname: configure file name

Reimplemented from ophSig.

Definition at line 225 of file ophSigPU.cpp.

226 {
227  return false;
228 }

◆ release() [1/2]

unsigned long Base::release ( void  )
inlineinherited

Call release() when reference is finished.

Definition at line 80 of file openholo/src/Base.h.

80  {
81  if (!refCnt) {
82  ophFree();
83  delete this;
84  return 0;
85  }
86  return refCnt--;
87  }

◆ release() [2/2]

unsigned long Base::release ( void  )
inlineinherited

Call release() when reference is finished.

Definition at line 80 of file Reference/include/Base.h.

80  {
81  if (!refCnt) {
82  ophFree();
83  delete this;
84  return 0;
85  }
86  return refCnt--;
87  }

◆ runPU() [1/2]

bool ophSigPU::runPU ( void  )

Run phase unwrapping algorithm.

Definition at line 176 of file ophSigPU.cpp.

177 {
178  matrix<Real> residue(Nr,Nc);
179  residue.zeros();
180  matrix<Real> branchcut(Nr, Nc);
181  branchcut.zeros();
182  phaseResidues(residue);
183  branchCuts(residue, branchcut);
184  floodFill(branchcut);
185  return false;
186 }

◆ runPU() [2/2]

bool ophSigPU::runPU ( void  )

Run phase unwrapping algorithm.

◆ save() [1/2]

bool ophSig::save ( const char *  real,
const char *  imag 
)
inherited

Save data as bmp or bin file.

Parameters
realreal data file name
imagimag data file name
bitpixelbit per pixel
Returns
if works well return 0 or error occurs return -1

◆ save() [2/2]

bool ophSig::save ( const char *  real,
const char *  imag 
)
inherited

Save data as bmp or bin file.

Parameters
realreal data file name
imagimag data file name
bitpixelbit per pixel
Returns
if works well return 0 or error occurs return -1

Definition at line 495 of file ophSig.cpp.

496 {
497  string realname = real;
498  string imagname = imag;
499 
500  char* RGB_name[3] = { "","","" };
501 
502  if (_wavelength_num > 1) {
503  RGB_name[0] = "_B";
504  RGB_name[1] = "_G";
505  RGB_name[2] = "_R";
506  }
507 
508  int checktype = static_cast<int>(realname.rfind("."));
509  string type = realname.substr(checktype + 1, realname.size());
510  if (type == "bin")
511  {
512  double *realdata = new double[context_.pixel_number[_X] * context_.pixel_number[_Y]];
513  double *imagdata = new double[context_.pixel_number[_X] * context_.pixel_number[_Y]];
514 
515  for (int z = 0; z < _wavelength_num; z++)
516  {
517  realname = real;
518  imagname = imag;
519  realname.insert(checktype, RGB_name[z]);
520  imagname.insert(checktype, RGB_name[z]);
521  std::ofstream cos(realname.c_str(), std::ios::binary);
522  std::ofstream sin(imagname.c_str(), std::ios::binary);
523 
524  if (!cos.is_open()) {
525  LOG("real file not found.\n");
526  cos.close();
527  delete[] realdata;
528  delete[] imagdata;
529  return FALSE;
530  }
531 
532  if (!sin.is_open()) {
533  LOG("imag file not found.\n");
534  sin.close();
535  delete[] realdata;
536  delete[] imagdata;
537  return FALSE;
538  }
539 
540  for (int i = 0; i < context_.pixel_number[_X]; i++)
541  {
542  for (int j = 0; j < context_.pixel_number[_Y]; j++)
543  {
544  realdata[i + j * context_.pixel_number[_X]] = ComplexH[z](i, j)._Val[_RE];
545  imagdata[i + j * context_.pixel_number[_X]] = ComplexH[z](i, j)._Val[_IM];
546  }
547  }
548  cos.write(reinterpret_cast<const char*>(realdata), sizeof(double) * context_.pixel_number[_X] * context_.pixel_number[_Y]);
549  sin.write(reinterpret_cast<const char*>(imagdata), sizeof(double) * context_.pixel_number[_X] * context_.pixel_number[_Y]);
550 
551  cos.close();
552  sin.close();
553  }
554  delete[]realdata;
555  delete[]imagdata;
556 
557  LOG("Writing Openholo Complex Field...%s, %s", realname.c_str(), imagname.c_str());
558  }
559  else {
560  LOG("failed : The Invalid data type! - %s\n", type);
561  }
562  return TRUE;
563 }

◆ saveAsImg() [1/2]

int Openholo::saveAsImg ( const char *  fname,
uint8_t  bitsperpixel,
uchar *  src,
int  pic_width,
int  pic_height 
)
virtualinherited

Function for creating image files.

Parameters
constchar* Output file name
uint8_tBit per pixel
unsignedchar* Source of Image file's data
intNumber of pixel - width
intNumber of pixel - height
Returns
int return -1 : Failed to save image file return 1 : Success to save image file

Definition at line 93 of file Openholo.cpp.

94 {
95  LOG("Saving...%s...", fname);
96  auto start = CUR_TIME;
97 
98  int _width = pic_width, _height = pic_height;
99 
100  int _pixelbytesize = _height * _width * bitsperpixel / 8;
101  int _filesize = _pixelbytesize + sizeof(bitmap);
102 
103  FILE *fp;
104  fopen_s(&fp, fname, "wb");
105  if (fp == nullptr) return -1;
106 
107  bitmap *pbitmap = (bitmap*)calloc(1, sizeof(bitmap));
108  memset(pbitmap, 0x00, sizeof(bitmap));
109 
110  pbitmap->fileheader.signature[0] = 'B';
111  pbitmap->fileheader.signature[1] = 'M';
112  pbitmap->fileheader.filesize = _filesize;
113  pbitmap->fileheader.fileoffset_to_pixelarray = sizeof(bitmap);
114 
115  for (int i = 0; i < 256; i++) {
116  pbitmap->rgbquad[i].rgbBlue = i;
117  pbitmap->rgbquad[i].rgbGreen = i;
118  pbitmap->rgbquad[i].rgbRed = i;
119  }
120 
121  pbitmap->bitmapinfoheader.dibheadersize = sizeof(bitmapinfoheader);
122  pbitmap->bitmapinfoheader.width = _width;
123  pbitmap->bitmapinfoheader.height = _height;
124  pbitmap->bitmapinfoheader.planes = OPH_PLANES;
125  pbitmap->bitmapinfoheader.bitsperpixel = bitsperpixel;
126  pbitmap->bitmapinfoheader.compression = OPH_COMPRESSION;
127  pbitmap->bitmapinfoheader.imagesize = _pixelbytesize;
128  pbitmap->bitmapinfoheader.ypixelpermeter = Y_PIXEL_PER_METER;
129  pbitmap->bitmapinfoheader.xpixelpermeter = X_PIXEL_PER_METER;
130  pbitmap->bitmapinfoheader.numcolorspallette = 256;
131  fwrite(pbitmap, 1, sizeof(bitmap), fp);
132 
133  fwrite(src, 1, _pixelbytesize, fp);
134  fclose(fp);
135  free(pbitmap);
136 
137  auto end = CUR_TIME;
138 
139  auto during = ((std::chrono::duration<Real>)(end - start)).count();
140 
141  LOG("%.5lfsec...done\n", during);
142 
143  return 1;
144 }

◆ saveAsImg() [2/2]

virtual int Openholo::saveAsImg ( const char *  fname,
uint8_t  bitsperpixel,
uchar *  src,
int  pic_width,
int  pic_height 
)
virtualinherited

Function for creating image files.

Parameters
constchar* Output file name
uint8_tBit per pixel
unsignedchar* Source of Image file's data
intNumber of pixel - width
intNumber of pixel - height
Returns
int return -1 : Failed to save image file return 1 : Success to save image file

◆ saveAsOhc() [1/2]

int ophSig::saveAsOhc ( const char *  fname)
virtualinherited

Function to write OHC file.

Reimplemented from Openholo.

Definition at line 345 of file ophSig.cpp.

346 {
347  std::string fullname = fname;
348  if (checkExtension(fname, ".ohc") == 0) fullname.append(".ohc");
349  OHC_encoder->setFileName(fullname.c_str());
350 
351  OHC_encoder->setNumOfPixel(context_.pixel_number[_X], context_.pixel_number[_Y]);
352 
353  OHC_encoder->setFieldEncoding(FldStore::Directly, FldCodeType::RI);
354 
355  OHC_encoder->setNumOfWavlen(_wavelength_num);
356 
357  for (int i = _wavelength_num - 1; i >= 0; i--)
358  {
359  //int wl = context_.wave_length[i] * 1000000000;
360  OHC_encoder->setWavelength(context_.wave_length[i], LenUnit::nm);
361 
362  OHC_encoder->addComplexFieldData(ComplexH[i]);
363  }
364 
365  if (!OHC_encoder->save()) return -1;
366 
367  return 1;
368 }
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ saveAsOhc() [2/2]

int ophSig::saveAsOhc ( const char *  fname)
virtualinherited

Function to write OHC file.

Reimplemented from Openholo.

◆ savePhaseUnwrapped() [1/2]

bool ophSigPU::savePhaseUnwrapped ( const char *  fname)

Save the unwrapped phase data to image file.

Parameters
fname: image file name where the unwrapped phase data will be stored

◆ savePhaseUnwrapped() [2/2]

bool ophSigPU::savePhaseUnwrapped ( const char *  fname)

Save the unwrapped phase data to image file.

Parameters
fname: image file name where the unwrapped phase data will be stored

Definition at line 188 of file ophSigPU.cpp.

189 {
190  oph::uchar* phaseData;
191  phaseData = (oph::uchar*)malloc(sizeof(oph::uchar) * Nr * Nc);
192 
193  string fnamestr = fname;
194 
195  double maxPhase = 0;
196  double minPhase = 0;
197  for (int i = 0; i < Nr; i++)
198  {
199  for (int j = 0; j < Nc; j++)
200  {
201  if (PhaseUnwrapped(i, j) > maxPhase)
202  {
203  maxPhase = PhaseUnwrapped(i, j);
204  }
205  if (PhaseUnwrapped(i, j) < minPhase)
206  {
207  minPhase = PhaseUnwrapped(i, j);
208  }
209  }
210  }
211 
212 
213  for (int i = 0; i < Nr; i++)
214  {
215  for (int j = 0; j < Nc; j++)
216  {
217  phaseData[i*Nc + j] = (uchar)(((PhaseUnwrapped(Nr - i -1,j)-minPhase)/(maxPhase-minPhase))*255.0);
218  }
219  }
220  saveAsImg(fnamestr.c_str(), 8, phaseData, Nc, Nr);
221  return TRUE;
222 }
virtual int saveAsImg(const char *fname, uint8_t bitsperpixel, uchar *src, int pic_width, int pic_height)
Function for creating image files.
Definition: Openholo.cpp:93

◆ setPixelNumberOHC() [1/2]

void Openholo::setPixelNumberOHC ( const ivec2  pixel_number)
inlineprotectedinherited

getter/setter for OHC file read and write

Definition at line 264 of file openholo/src/Openholo.h.

265  { OHC_encoder->setNumOfPixel(pixel_number); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ setPixelNumberOHC() [2/2]

void Openholo::setPixelNumberOHC ( const ivec2  pixel_number)
inlineprotectedinherited

getter/setter for OHC file read and write

Definition at line 264 of file Reference/include/Openholo.h.

265  { OHC_encoder->setNumOfPixel(pixel_number); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ setPUparam() [1/2]

bool ophSigPU::setPUparam ( int  maxBoxRadius)

Set parameters for Goldstein branchcut algorithm.

Parameters
maxBoxRadius: maximum box radius for neighboring residue search

Definition at line 7 of file ophSigPU.cpp.

8 {
9  MaxBoxRadius = maxBoxRadius;
10  return false;
11 }

◆ setPUparam() [2/2]

bool ophSigPU::setPUparam ( int  maxBoxRadius)

Set parameters for Goldstein branchcut algorithm.

Parameters
maxBoxRadius: maximum box radius for neighboring residue search

◆ sigConvertCAC()

bool ophSig::sigConvertCAC ( double  red,
double  green,
double  blue 
)
inherited

Function for Chromatic aberration compensation filter .

Returns
if works well return 0 or error occurs return -1

◆ sigConvertHPO()

bool ophSig::sigConvertHPO ( )
inherited

Function for convert complex hologram to horizontal parallax only hologram .

Returns
if works well return 0 or error occurs return -1

◆ sigConvertOffaxis()

bool ophSig::sigConvertOffaxis ( )
inherited

Function for Convert complex hologram to off-axis hologram .

Returns
if works well return 0 or error occurs return -1

◆ sigGetParamAT()

double ophSig::sigGetParamAT ( )
inherited

Extraction of distance parameter using axis transfomation .

Returns
result distance

◆ sigGetParamSF()

double ophSig::sigGetParamSF ( float  zMax,
float  zMin,
int  sampN,
float  th 
)
inherited

Extraction of distance parameter using sharpness functions .

Parameters
zMaxmaximum value of distance on z axis
zMinminimum value of distance on z axis
sampNcount of search step
ththreshold value
Returns
result distance

Member Data Documentation

◆ OHC_encoder

ImgEncoderOhc * Openholo::OHC_encoder
protectedinherited

OHC file format Variables for read and write.

Definition at line 257 of file openholo/src/Openholo.h.


The documentation for this class was generated from the following files: