57 ivec2 bufferSize(nx, ny);
63 for (
int x = 0; x < bufferSize[
_X]; x++) {
64 for (
int y = 0; y < bufferSize[
_Y]; y++) {
65 (*dst)[idx] = src[x][y];
72 ivec2 bufferSize(nx, ny);
77 for (
int x = 0; x < bufferSize[
_X]; x++) {
78 for (
int y = 0; y < bufferSize[
_Y]; y++) {
79 (*dst)[idx] = src[x][y];
92 if (src.size != dst.size) {
93 dst.resize(src.size[
_X], src.size[
_Y]);
95 int size = src.size[
_Y];
97 for (
int i = 0, j = 0; j < dst.size[
_Y]; j++)
99 if ((Xq[j]) >= (X[size - 2]))
105 while ((Xq[j]) >(X[i + 1])) i++;
107 dst(0, j)[
_RE] = src(0, i).real() + (src(0, i + 1).real() - src(0, i).real()) / (X[i + 1] - X[i]) * (Xq[j] - X[i]);
108 dst(0, j)[
_IM] = src(0, i).imag() + (src(0, i + 1).imag() - src(0, i).imag()) / (X[i + 1] - X[i]) * (Xq[j] - X[i]);
115 if (src.size != dst.size) {
116 dst.resize(src.size[
_X], src.size[
_Y]);
118 fftw_complex *fft_in = (fftw_complex*)fftw_malloc(
sizeof(fftw_complex) * src.size[
_Y]);
119 fftw_complex *fft_out = (fftw_complex*)fftw_malloc(
sizeof(fftw_complex) * src.size[
_Y]);
121 for (
int i = 0; i < src.size[
_Y]; i++) {
122 fft_in[i][
_RE] = src(0, i).real();
123 fft_in[i][
_IM] = src(0, i).imag();
126 fftw_plan plan = fftw_plan_dft_1d(src.size[
_Y], fft_in, fft_out, sign, flag);
131 for (
int i = 0; i < src.size[
_Y]; i++) {
132 dst(0, i)[
_RE] = fft_out[i][
_RE];
133 dst(0, i)[
_IM] = fft_out[i][
_IM];
138 for (
int i = 0; i < src.size[
_Y]; i++) {
139 dst(0, i)[
_RE] = fft_out[i][
_RE] / src.size[
_Y];
140 dst(0, i)[
_IM] = fft_out[i][
_IM] / src.size[
_Y];
144 fftw_destroy_plan(plan);
151 if (src.size != dst.size) {
152 dst.resize(src.size[
_X], src.size[
_Y]);
155 fftw_complex *fft_in = (fftw_complex*)fftw_malloc(
sizeof(fftw_complex) * src.size[
_X] * src.size[
_Y]);
156 fftw_complex *fft_out = (fftw_complex*)fftw_malloc(
sizeof(fftw_complex) * src.size[
_X] * src.size[
_Y]);
158 for (
int i = 0; i < src.size[
_X]; i++) {
159 for (
int j = 0; j < src.size[
_Y]; j++) {
160 fft_in[src.size[
_Y] * i + j][
_RE] = src(i, j).real();
161 fft_in[src.size[
_Y] * i + j][
_IM] = src(i, j).imag();
165 fftw_plan plan = fftw_plan_dft_2d(src.size[
_X], src.size[
_Y], fft_in, fft_out, sign, flag);
170 for (
int i = 0; i < src.size[
_X]; i++) {
171 for (
int j = 0; j < src.size[
_Y]; j++) {
172 dst(i, j)[
_RE] = fft_out[src.size[
_Y] * i + j][
_RE];
173 dst(i, j)[
_IM] = fft_out[src.size[
_Y] * i + j][
_IM];
179 for (
int i = 0; i < src.size[
_X]; i++) {
180 for (
int j = 0; j < src.size[
_Y]; j++) {
181 dst(i, j)[
_RE] = fft_out[src.size[
_Y] * i + j][
_RE] / (src.size[
_X] * src.size[
_Y]);
182 dst(i, j)[
_IM] = fft_out[src.size[
_Y] * i + j][
_IM] / (src.size[
_X] * src.size[
_Y]);
188 fftw_destroy_plan(plan);
200 std::string fullname = fname;
205 vector<Real> wavelengthArray;
229 std::string fullname = fname;
259 string realname = real;
260 string imagname = imag;
262 char* RGB_name[3] = { 0, };
263 const char* postfix =
"";
267 strcpy(RGB_name[0], postfix);
269 strcpy(RGB_name[1], postfix);
271 strcpy(RGB_name[2], postfix);
274 strcpy(RGB_name[0], postfix);
276 int checktype =
static_cast<int>(realname.rfind(
"."));
281 std::string realtype = realname.substr(checktype + 1, realname.size());
282 std::string imgtype = imagname.substr(checktype + 1, realname.size());
286 if (realtype != imgtype) {
287 LOG(
"failed : The data type between real and imaginary is different!\n");
290 if (realtype ==
"bmp")
298 if (realdata == 0 && imagdata == 0) {
299 cout <<
"failed : hologram data load was failed." << endl;
319 else if (realtype ==
"bin")
329 realname.insert(checktype, RGB_name[z]);
330 imagname.insert(checktype, RGB_name[z]);
332 ifstream freal(realname.c_str(), ifstream::binary);
333 ifstream fimag(imagname.c_str(), ifstream::binary);
357 LOG(
"Error: wrong type\n");
384 LOG(
"Reading Openholo Complex Field File...%s, %s\n", realname.c_str(), imagname.c_str());
393 string realname = real;
394 string imagname = imag;
396 char* RGB_name[3] = { 0, };
397 const char* postfix =
"";
401 strcpy(RGB_name[0], postfix);
403 strcpy(RGB_name[1], postfix);
405 strcpy(RGB_name[2], postfix);
408 strcpy(RGB_name[0], postfix);
410 int checktype =
static_cast<int>(realname.rfind(
"."));
411 string type = realname.substr(checktype + 1, realname.size());
421 realname.insert(checktype, RGB_name[z]);
422 imagname.insert(checktype, RGB_name[z]);
423 std::ofstream cos(realname.c_str(), std::ios::binary);
424 std::ofstream sin(imagname.c_str(), std::ios::binary);
426 if (!cos.is_open()) {
427 LOG(
"real file not found.\n");
434 if (!sin.is_open()) {
435 LOG(
"imag file not found.\n");
459 LOG(
"Writing Openholo Complex Field...%s, %s\n", realname.c_str(), imagname.c_str());
461 else if (type ==
"bmp")
465 int _pixelbytesize = 0;
471 _pixelbytesize = _height * _width;
475 _pixelbytesize = _height * _width * 3;
481 freal = fopen(realname.c_str(),
"wb");
482 fimag = fopen(imagname.c_str(),
"wb");
484 if ((freal ==
nullptr) || (fimag ==
nullptr))
486 LOG(
"file not found\n");
494 _filesize = _pixelbytesize +
sizeof(
bitmap8bit);
499 pbitmap->_fileheader.signature[0] =
'B';
500 pbitmap->_fileheader.signature[1] =
'M';
501 pbitmap->_fileheader.filesize = _filesize;
502 pbitmap->_fileheader.fileoffset_to_pixelarray =
sizeof(
bitmap8bit);
504 for (
int i = 0; i < 256; i++) {
505 pbitmap->_rgbquad[i].rgbBlue = i;
506 pbitmap->_rgbquad[i].rgbGreen = i;
507 pbitmap->_rgbquad[i].rgbRed = i;
512 for (
int i = _height - 1; i >= 0; i--)
514 for (
int j = 0; j < _width; j++)
528 double minVal, iminVal, maxVal, imaxVal;
540 for (
int i = _height - 1; i >= 0; i--)
542 for (
int j = 0; j < _width; j++)
544 realdata[i*_width + j] = (
uchar)((
ComplexH[0](_height - i - 1, j)[
_RE] - minVal) / (maxVal - minVal) * 255 + 0.5);
545 imagdata[i*_width + j] = (
uchar)((
ComplexH[0](_height - i - 1, j)[
_IM] - iminVal) / (imaxVal - iminVal) * 255 + 0.5);
550 pbitmap->_bitmapinfoheader.width = _width;
551 pbitmap->_bitmapinfoheader.height = _height;
552 pbitmap->_bitmapinfoheader.planes =
OPH_PLANES;
553 pbitmap->_bitmapinfoheader.bitsperpixel = bitpixel;
555 pbitmap->_bitmapinfoheader.imagesize = _pixelbytesize;
556 pbitmap->_bitmapinfoheader.ypixelpermeter = 0;
557 pbitmap->_bitmapinfoheader.xpixelpermeter = 0;
558 pbitmap->_bitmapinfoheader.numcolorspallette = 256;
560 fwrite(pbitmap, 1,
sizeof(
bitmap8bit), freal);
561 fwrite(realdata, 1, _pixelbytesize, freal);
563 fwrite(pbitmap, 1,
sizeof(
bitmap8bit), fimag);
564 fwrite(imagdata, 1, _pixelbytesize, fimag);
584 double minVal, iminVal, maxVal, imaxVal;
586 for (
int z = 0; z < 3; z++)
604 for (
int i = _height - 1; i >= 0; i--)
606 for (
int j = 0; j < _width; j++)
608 realdata[3 * j + 3 * i * _width + z] = (
uchar)((
ComplexH[z](_height - i - 1, j)[
_RE] - minVal) / (maxVal - minVal) * 255);
609 imagdata[3 * j + 3 * i * _width + z] = (
uchar)((
ComplexH[z](_height - i - 1, j)[
_IM] - iminVal) / (imaxVal - iminVal) * 255);
626 fwrite(realdata, 1, _pixelbytesize, freal);
630 fwrite(imagdata, 1, _pixelbytesize, fimag);
640 std::cout <<
"file save bmp complete\n" << endl;
644 LOG(
"failed : The Invalid data type! - %s\n", type.c_str());
651 string fullname = fname;
653 char* RGB_name[3] = { 0, };
654 const char* postfix =
"";
658 strcpy(RGB_name[0], postfix);
660 strcpy(RGB_name[1], postfix);
662 strcpy(RGB_name[2], postfix);
665 strcpy(RGB_name[0], postfix);
667 int checktype =
static_cast<int>(fullname.rfind(
"."));
669 if (fullname.substr(checktype + 1, fullname.size()) ==
"bmp")
675 double maxIntensity = 0.0;
676 double realVal = 0.0;
677 double imagVal = 0.0;
678 double intensityVal = 0.0;
686 intensityVal = realVal*realVal + imagVal*imagVal;
687 if (intensityVal > maxIntensity) {
688 maxIntensity = intensityVal;
698 intensityVal = realVal*realVal + imagVal*imagVal;
709 else if (fullname.substr(checktype + 1, fullname.size()) ==
"bin")
716 fullname.insert(checktype, RGB_name[z]);
717 std::ofstream cos(fullname.c_str(), std::ios::binary);
719 if (!cos.is_open()) {
720 LOG(
"Error: file name not found.\n");
740 LOG(
"Writing Openholo Complex Field...%s\n", fullname.c_str());
757 for (
int i = _height - 1; i >= 0; i--)
759 for (
int j = 0; j < _width; j++)
761 if (abs_data[0].mat[_height - i - 1][j][
_RE] < 0)
763 abs_data[0].
mat[_height - i - 1][j][
_RE] = 0;
768 double minVal, iminVal, maxVal, imaxVal;
769 for (
int j = 0; j < abs_data[0].
size[
_Y]; j++) {
770 for (
int i = 0; i < abs_data[0].
size[
_X]; i++) {
771 if ((i == 0) && (j == 0))
773 minVal = abs_data[0](i, j)[
_RE];
774 maxVal = abs_data[0](i, j)[
_RE];
777 if (abs_data[0](i, j)[
_RE] < minVal)
779 minVal = abs_data[0](i, j).real();
781 if (abs_data[0](i, j)[
_RE] > maxVal)
783 maxVal = abs_data[0](i, j).real();
788 for (
int i = _height - 1; i >= 0; i--)
790 for (
int j = 0; j < _width; j++)
792 data[i*_width + j] = (
uchar)((abs_data[0](_height - i - 1, j)[
_RE] - minVal) / (maxVal - minVal) * 255 + 0.5);
799 double minVal, iminVal, maxVal, imaxVal;
800 for (
int z = 0; z < 3; z++)
803 for (
int j = 0; j < abs_data[0].
size[
_Y]; j++) {
804 for (
int i = 0; i < abs_data[0].
size[
_X]; i++) {
805 if ((i == 0) && (j == 0))
807 minVal = abs_data[0](i, j)[
_RE];
808 maxVal = abs_data[0](i, j)[
_RE];
811 if (abs_data[0](i, j)[
_RE] < minVal)
813 minVal = abs_data[0](i, j)[
_RE];
815 if (abs_data[0](i, j)[
_RE] > maxVal)
817 maxVal = abs_data[0](i, j)[
_RE];
823 for (
int i = _height - 1; i >= 0; i--)
825 for (
int j = 0; j < _width; j++)
827 data[3 * j + 3 * i * _width + z] = (
uchar)((abs_data[0](_height - i - 1, j)[
_RE] - minVal) / (maxVal - minVal) * 255);
838 for (
int i = _height - 1; i >= 0; i--)
840 for (
int j = 0; j < _width; j++)
849 double minVal, iminVal, maxVal, imaxVal;
852 if ((i == 0) && (j == 0))
869 for (
int i = _height - 1; i >= 0; i--)
871 for (
int j = 0; j < _width; j++)
873 data[i*_width + j] = (
uchar)((
ComplexH[0](_height - i - 1, j)[
_RE] - minVal) / (maxVal - minVal) * 255 + 0.5);
880 double minVal, iminVal, maxVal, imaxVal;
881 for (
int z = 0; z < 3; z++)
885 if ((i == 0) && (j == 0))
903 for (
int i = _height - 1; i >= 0; i--)
905 for (
int j = 0; j < _width; j++)
907 data[3 * j + 3 * i * _width + z] = (
uchar)((
ComplexH[z](_height - i - 1, j)[
_RE] - minVal) / (maxVal - minVal) * 255);
918 for (
int i = _height - 1; i >= 0; i--)
920 for (
int j = 0; j < _width; j++)
929 double minVal, iminVal, maxVal, imaxVal;
932 if ((i == 0) && (j == 0))
949 for (
int i = _height - 1; i >= 0; i--)
951 for (
int j = 0; j < _width; j++)
953 data[i*_width + j] = (
uchar)((
ComplexH[0](_height - i - 1, j)[
_IM] - minVal) / (maxVal - minVal) * 255 + 0.5);
960 double minVal, iminVal, maxVal, imaxVal;
961 for (
int z = 0; z < 3; z++)
965 if ((i == 0) && (j == 0))
983 for (
int i = _height - 1; i >= 0; i--)
985 for (
int j = 0; j < _width; j++)
987 data[3 * j + 3 * i * _width + z] = (
uchar)((
ComplexH[z](_height - i - 1, j)[
_IM] - minVal) / (maxVal - minVal) * 255);
1001 std::cout <<
"Start Single Core CPU" << endl;
1005 std::cout <<
"Start Multi Core GPU" << std::endl;
1009 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
1010 LOG(
"Implement time : %.5lf sec\n", during_time);
1018 std::cout <<
"Start Single Core CPU" << endl;
1023 std::cout <<
"Start Multi Core GPU" << std::endl;
1030 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
1031 LOG(
"Implement time : %.5lf sec\n", during_time);
1039 std::cout <<
"Start Single Core CPU" << endl;
1044 std::cout <<
"Start Multi Core GPU" << std::endl;
1049 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
1050 LOG(
"Implement time : %.5lf sec\n", during_time);
1058 std::cout <<
"Start Single Core CPU" << endl;
1063 std::cout <<
"Start Multi Core GPU" << std::endl;
1075 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
1076 LOG(
"Implement time : %.5lf sec\n", during_time);
1085 std::cout <<
"Start Single Core CPU" << endl;
1090 std::cout <<
"Start Multi Core GPU" << std::endl;
1095 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
1096 LOG(
"Implement time : %.5lf sec\n", during_time);
1110 for (
int i = 0; i < nx; i++)
1113 for (
int j = 0; j < ny; j++)
1121 H1(i, j) = ((*ComplexH)(i, j) * F)[
_RE];
1131 for (
int i = 0; i < nx; i++)
1133 for (
int j = 0; j < ny; j++)
1135 (*ComplexH)(i, j)[
_RE] = H1(i, j);
1136 (*ComplexH)(i, j)[
_IM] = 0;
1154 int xshift = nx / 2;
1155 int yshift = ny / 2;
1159 Real_t NA_g = NA * redRate;
1165 Real Rephase = -(1 / (4 *
M_PI)*pow((wl / NA_g), 2));
1166 Real Imphase = ((1 / (4 *
M_PI))*depth*wl);
1168 for (
int i = 0; i < ny; i++)
1170 int ii = (i + yshift) % ny;
1172 for (
int j = 0; j < nx; j++)
1175 int jj = (j + xshift) % nx;
1176 F1(jj, ii)[
_RE] = std::exp(Rephase*pow(y, 2))*cos(Imphase*pow(y, 2));
1177 F1(jj, ii)[
_IM] = std::exp(Rephase*pow(y, 2))*sin(Imphase*pow(y, 2));
1214 int xshift = nx / 2;
1215 int yshift = ny / 2;
1217 for (
int i = 0; i < ny; i++)
1219 int ii = (i + yshift) % ny;
1221 for (
int j = 0; j < nx; j++)
1225 int jj = (j + xshift) % nx;
1227 FFZP(jj, ii)[
_RE] = cos(sigmaf * (pow(x, 2) + pow(y, 2)));
1228 FFZP(jj, ii)[
_IM] = -sin(sigmaf * (pow(x, 2) + pow(y, 2)));
1275 LOG(
"file's extension is not 'xml'\n");
1278 auto ret = xml_doc.
LoadFile(fname);
1281 LOG(
"Failed to load file \"%s\"\n", fname);
1319 int xshift = nx / 2;
1320 int yshift = ny / 2;
1331 for (i = 0; i < ny; i++)
1333 int ii = (i + yshift) % ny;
1336 for (j = 0; j < nx; j++)
1339 int jj = (j + xshift) % nx;
1340 double temp = FH(jj, ii)[
_RE];
1341 FH(jj, ii)[
_RE] = cos(sigmaf * (pow(x, 2) + pow(y, 2))) * FH(jj, ii)[
_RE] - sin(sigmaf * (pow(x, 2) + pow(y, 2))) * FH(jj, ii)[
_IM];
1342 FH(jj, ii)[
_IM] = sin(sigmaf * (pow(x, 2) + pow(y, 2))) * temp + cos(sigmaf * (pow(x, 2) + pow(y, 2))) * FH(jj, ii)[
_IM];
1359 int xshift = nx / 2;
1360 int yshift = ny / 2;
1367 for (i = 0; i < ny; i++)
1369 int ii = (i + yshift) % ny;
1372 for (j = 0; j < nx; j++)
1375 int jj = (j + xshift) % nx;
1376 double temp = FH(jj, ii)[
_RE];
1377 FH(jj, ii)[
_RE] = cos(sigmaf * (pow(x, 2) + pow(y, 2))) * FH(jj, ii)[
_RE] - sin(sigmaf * (pow(x, 2) + pow(y, 2))) * FH(jj, ii)[
_IM];
1378 FH(jj, ii)[
_IM] = sin(sigmaf * (pow(x, 2) + pow(y, 2))) * temp + cos(sigmaf * (pow(x, 2) + pow(y, 2))) * FH(jj, ii)[
_IM];
1432 for (i = 0; i < nx; i++)
1434 for (j = 0; j < ny; j++)
1440 Flr(i, j)[
_RE] = (*ComplexH)(i, j)[
_RE];
1441 Fli(i, j)[
_RE] = (*ComplexH)(i, j)[
_IM];
1450 int xshift = nx / 2;
1451 int yshift = ny / 2;
1453 for (i = 0; i < nx; i++)
1455 int ii = (i + xshift) % nx;
1456 for (j = 0; j < ny; j++)
1458 int jj = (j + yshift) % ny;
1459 Hsyn(i, j)[
_RE] = Flr(i, j)[
_RE] * G(i, j);
1460 Hsyn(i, j)[
_IM] = Fli(i, j)[
_RE] * G(i, j);
1466 Fo(ii, jj) = pow(Hsyn(i, j), 2) / (pow(
abs(Hsyn(i, j)), 2) + pow(10, -300));
1472 tn.resize(t.size());
1475 int size = (int)tn.size();
1476 for (
int i = 0; i < size; i++)
1478 tn.at(i) = pow(t.at(i), 0.5);
1479 Fon(0, i)[
_RE] = Fo(nx / 2 - 1, nx / 2 - 1 + i)[
_RE];
1487 Ab_yn_half.
resize(1, nx / 4 + 1);
1489 for (
int i = 0; i < nx / 4 + 1; i++)
1491 Ab_yn_half(0, i) = Ab_yn(0, nx / 4 + i - 1)[
_RE];
1492 if (i == 0) max = Ab_yn_half(0, 0);
1495 if (Ab_yn_half(0, i) > max)
1497 max = Ab_yn_half(0, i);
1503 index = -(((index + 1) - 120) / 10) / 140 + 0.1;
1517 Real dz = (zMax - zMin) / sampN;
1528 for (n = 0; n < sampN + 1; n++)
1531 z = ((n)* dz + zMin);
1535 for (i = 0; i < nx - 2; i++)
1537 for (j = 0; j < ny - 2; j++)
1539 ret1 =
abs(I(i + 2, j)[
_RE] - I(i, j)[
_RE]);
1540 ret2 =
abs(I(i, j + 2)[
_RE] - I(i, j)[
_RE]);
1541 if (ret1 >= th) { f += ret1 * ret1; }
1542 else if (ret2 >= th) { f += ret2 * ret2; }
1559 string fname0str = fname0;
1560 string fname90str = fname90;
1561 string fname180str = fname180;
1562 string fname270str = fname270;
1563 int checktype =
static_cast<int>(fname0str.rfind(
"."));
1564 OphRealField f0Mat[3], f90Mat[3], f180Mat[3], f270Mat[3];
1566 std::string f0type = fname0str.substr(checktype + 1, fname0str.size());
1568 uint16_t bitsperpixel;
1572 if (f0type ==
"bmp")
1574 FILE *f0, *f90, *f180, *f270;
1575 f0 = fopen(fname0str.c_str(),
"rb");
1576 f90 = fopen(fname90str.c_str(),
"rb");
1577 f180 = fopen(fname180str.c_str(),
"rb");
1578 f270 = fopen(fname270str.c_str(),
"rb");
1581 LOG(
"bmp file open fail! (phase shift = 0)\n");
1586 LOG(
"bmp file open fail! (phase shift = 90)\n");
1591 LOG(
"bmp file open fail! (phase shift = 180)\n");
1596 LOG(
"bmp file open fail! (phase shift = 270)\n");
1605 LOG(
"bmp header is empty!\n");
1610 LOG(
"check your parameter file!\n");
1615 LOG(
"image size is different!\n");
1667 nRead = fread(f0data,
sizeof(
uchar), size, f0);
1668 nRead = fread(f90data,
sizeof(
uchar), size, f90);
1669 nRead = fread(f180data,
sizeof(
uchar), size, f180);
1670 nRead = fread(f270data,
sizeof(
uchar), size, f270);
1681 for (
int j = 0; j < static_cast<int>(
hInfo.
width); j++)
1686 int idx2 = i * nLine + bpp * j + z;
1687 f0Mat[z](idx, j) = (
double)f0data[idx2];
1688 f90Mat[z](idx, j) = (
double)f90data[idx2];
1689 f180Mat[z](idx, j) = (
double)f180data[idx2];
1690 f270Mat[z](idx, j) = (
double)f270data[idx2];
1694 LOG(
"PSDH file load complete!\n");
1704 LOG(
"wrong type (only BMP supported)\n");
1708 double normalizefactor = 1. / 256.;
1715 ComplexH[z][j][i][
_RE] = (f0Mat[z][j][i] - f180Mat[z][j][i])*normalizefactor;
1716 ComplexH[z][j][i][
_IM] = (f90Mat[z][j][i] - f270Mat[z][j][i])*normalizefactor;
1721 LOG(
"complex field obtained from 4 psdh\n");
1725 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
1727 LOG(
"Implement time : %.5lf sec\n", during_time);
1733 const char* fname0,
const char* fname1,
1734 const char* fname2,
const char* fnameOI,
1735 const char* fnameRI,
int nIter)
1738 string fname0str = fname0;
1739 string fname1str = fname1;
1740 string fname2str = fname2;
1741 string fnameOIstr = fnameOI;
1742 string fnameRIstr = fnameRI;
1743 int checktype =
static_cast<int>(fname0str.rfind(
"."));
1744 OphRealField f0Mat[3], f1Mat[3], f2Mat[3], fOIMat[3], fRIMat[3];
1746 std::string f0type = fname0str.substr(checktype + 1, fname0str.size());
1748 uint16_t bitsperpixel;
1752 if (f0type ==
"bmp")
1754 FILE *f0, *f1, *f2, *fOI, *fRI;
1755 f0 = fopen(fname0str.c_str(),
"rb");
1756 f1 = fopen(fname1str.c_str(),
"rb");
1757 f2 = fopen(fname2str.c_str(),
"rb");
1758 fOI = fopen(fnameOIstr.c_str(),
"rb");
1759 fRI = fopen(fnameRIstr.c_str(),
"rb");
1762 LOG(
"bmp file open fail! (first interference pattern)\n");
1767 LOG(
"bmp file open fail! (second interference pattern)\n");
1772 LOG(
"bmp file open fail! (third interference pattern)\n");
1777 LOG(
"bmp file open fail! (object wave intensity pattern)\n");
1782 LOG(
"bmp file open fail! (reference wave intensity pattern)\n");
1801 LOG(
"bmp header is empty!\n");
1806 LOG(
"check your parameter file!\n");
1811 LOG(
"image size is different!\n");
1871 nRead = fread(f0data,
sizeof(
uchar), size, f0);
1872 nRead = fread(f1data,
sizeof(
uchar), size, f1);
1873 nRead = fread(f2data,
sizeof(
uchar), size, f2);
1874 nRead = fread(fOIdata,
sizeof(
uchar), size, fOI);
1875 nRead = fread(fRIdata,
sizeof(
uchar), size, fRI);
1887 for (
int j = 0; j < static_cast<int>(
hInfo.
width); j++)
1892 size_t idx2 = i * size + bpp * j + z;
1893 f0Mat[z](idx, j) = (
double)f0data[idx2];
1894 f1Mat[z](idx, j) = (
double)f1data[idx2];
1895 f2Mat[z](idx, j) = (
double)f2data[idx2];
1896 fOIMat[z](idx, j) = (
double)fOIdata[idx2];
1897 fRIMat[z](idx, j) = (
double)fRIdata[idx2];
1902 LOG(
"PSDH_3ArbStep file load complete!\n");
1913 LOG(
"wrong type (only BMP supported)\n");
1918 double P[2] = { 0.0, };
1919 double C[2] = { 2.0/
M_PI, 2.0/
M_PI };
1920 double alpha[2] = { 0.0, };
1921 double ps[3] = { 0.0, };
1924 const int nXY = nX * nY;
1935 double sin2m1h, sin2m0h, sin1m0h, sin0p1h, sin0p2h, cos0p1h, cos0p2h, sin1p2h, cos1p2h;
1946 for (
int i = 0; i < nX; i++)
1948 for (
int j = 0; j < nY; j++)
1950 I01Mat[j][i] = (f0Mat[z][j][i] - f1Mat[z][j][i]) / 255.;
1951 I02Mat[j][i] = (f0Mat[z][j][i] - f2Mat[z][j][i]) / 255.;
1952 I12Mat[j][i] = (f1Mat[z][j][i] - f2Mat[z][j][i]) / 255.;
1953 OAMat[j][i] = sqrt(fOIMat[z][j][i] / 255.);
1954 RAMat[j][i] = sqrt(fRIMat[z][j][i] / 255.);
1959 for (
int i = 0; i < nX; i++)
1961 for (
int j = 0; j < nY; j++)
1963 P[0] +=
abs(I01Mat[j][i] / OAMat[j][i] / RAMat[j][i]);
1964 P[1] +=
abs(I12Mat[j][i] / OAMat[j][i] / RAMat[j][i]);
1967 P[0] = P[0] / (4.*((double) nXY));
1968 P[1] = P[1] / (4.*((double) nXY));
1969 LOG(
"P %f %f\n", P[0], P[1]);
1972 for (
int iter = 0; iter < nIter; iter++)
1974 LOG(
"C %d %f %f\n", iter, C[0], C[1]);
1975 LOG(
"ps %d %f %f %f\n", iter, ps[0], ps[1], ps[2]);
1977 alpha[0] = 2.*asin(P[0] / C[0]);
1978 alpha[1] = 2.*asin(P[1] / C[1]);
1981 ps[1] = ps[0] + alpha[0];
1982 ps[2] = ps[1] + alpha[1];
1984 sin2m1h = sin((ps[2] - ps[1]) / 2.);
1985 sin2m0h = sin((ps[2] - ps[0]) / 2.);
1986 sin1m0h = sin((ps[1] - ps[0]) / 2.);
1987 sin0p1h = sin((ps[0] + ps[1]) / 2.);
1988 sin0p2h = sin((ps[0] + ps[2]) / 2.);
1989 cos0p1h = cos((ps[0] + ps[1]) / 2.);
1990 cos0p2h = cos((ps[0] + ps[2]) / 2.);
1991 for (
int i = 0; i < nX; i++)
1993 for (
int j = 0; j < nY; j++)
1995 ComplexH[z][j][i][
_RE] = (1. / (4.*RAMat[j][i]*sin2m1h))*((cos0p1h / sin2m0h)*I02Mat[j][i] - (cos0p2h / sin1m0h)*I01Mat[j][i]);
1996 ComplexH[z][j][i][
_IM] = (1. / (4.*RAMat[j][i]*sin2m1h))*((sin0p1h / sin2m0h)*I02Mat[j][i] - (sin0p2h / sin1m0h)*I01Mat[j][i]);
2003 sin1p2h = sin((ps[1] + ps[2]) / 2.);
2004 cos1p2h = cos((ps[1] + ps[2]) / 2.);
2005 for (
int i = 0; i < nX; i++)
2007 for (
int j = 0; j < nY; j++)
2011 C[0] +=
abs(sinP*cos0p1h - cosP*sin0p1h);
2012 C[1] +=
abs(sinP*cos1p2h - cosP*sin1p2h);
2015 LOG(
"C1 %d %f %f\n", iter, C[0], C[1]);
2016 C[0] = C[0] / ((double)nXY);
2017 C[1] = C[1] / ((double)nXY);
2018 LOG(
"C2 %d %f %f\n", iter, C[0], C[1]);
2021 for (
int i = 0; i < nX; i++)
2023 for (
int j = 0; j < nY; j++)
2033 LOG(
"complex field obtained from 3 interference patterns\n");
2037 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
2039 LOG(
"Implement time : %.5lf sec\n", during_time);
bool save(const char *real, const char *imag)
Save data as bmp or bin file.
void abs(const oph::Complex< T > &src, oph::Complex< T > &dst)
void cField2Buffer(matrix< Complex< Real >> &src, Complex< Real > **dst, int nx, int ny)
Function for move data from matrix<Complex<Real>> to Complex<Real>
virtual bool saveAsImg(const char *fname, uint8_t bitsperpixel, uchar *src, int width, int height)
Function for creating image files.
bool sigConvertOffaxis(Real angleX, Real angleY)
Function for Convert complex hologram to off-axis hologram.
bool loadAsOhc(const char *fname)
Load data as ohc file.
bool cvtOffaxis_CPU(Real angleX, Real angleY)
void ColorField2Buffer(matrix< Complex< Real >> &src, Complex< Real > **dst, int nx, int ny)
Function for move Color data from matrix<Complex<Real>> to Complex<Real>
bool getComplexHFrom3ArbStepPSDH(const char *f0, const char *f1, const char *f2, const char *fOI, const char *fRI, int nIter)
Extraction of complex field from 3 phase shifted interference patterns with arbitrary unknown shifts...
matrix< T > & mulElem(matrix< T > &p)
double sigGetParamAT_GPU()
Extraction of distance parameter using axis transfomation by using GPU.
void fft1(matrix< Complex< T >> &src, matrix< Complex< T >> &dst, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Function for Fast Fourier transform 1D.
double sigGetParamSF(float zMax, float zMin, int sampN, float th)
Extraction of distance parameter using sharpness functions.
bool saveAsOhc(const char *fname)
Save data as ohc file.
bool sigConvertHPO_GPU(Real depth, Real_t redRate)
Function for convert complex hologram to horizontal parallax only hologram by using GPU...
double sigGetParamAT_CPU()
Extraction of distance parameter using axis transfomation by using CPU.
bool checkExtension(const char *fname, const char *ext)
Functions for extension checking.
bool propagationHolo(float depth)
Function for propagation hologram (class data)
structure for 2-dimensional integer vector and its arithmetic.
matrix< T > & resize(int x, int y)
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
void setMode(bool is_CPU)
Function for select device.
void fft2(matrix< Complex< T >> &src, matrix< Complex< T >> &dst, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Function for Fast Fourier transform 2D.
bool getComplexHFromPSDH(const char *fname0, const char *fname90, const char *fname180, const char *fname270)
Extraction of complex field from 4 phase shifted interference patterns.
bool readConfig(const char *fname)
Function for Read parameter.
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.
void setFieldEncoding(const FldStore _fldStore, const FldCodeType _fldCodeType)
void getComplexFieldData(OphComplexField &cmplx_field, uint wavelen_idx)
bool sigConvertHPO(Real depth, Real_t redRate)
Function for convert complex hologram to horizontal parallax only hologram.
ImgDecoderOhc * OHC_decoder
bool sigConvertCAC_CPU(double red, double green, double blue)
Function for Chromatic aberration compensation filter by using CPU .
bool sigConvertCAC(double red, double green, double blue)
Function for Chromatic aberration compensation filter.
double sigGetParamAT()
Extraction of distance parameter using axis transfomation.
bool Color_propagationHolo_GPU(float depth)
void addComplexFieldData(const OphComplexField &data)
OphComplexField * ComplexH
bool sigConvertCAC_GPU(double red, double green, double blue)
Function for Chromatic aberration compensation filter by using GPU.
void setNumOfWavlen(const uint n_wavlens)
oph::matrix< Complex< Real > > OphComplexField
void wavelength_Set(double wavelength)
bool sigConvertHPO_CPU(Real depth, Real_t redRate)
Function for convert complex hologram to horizontal parallax only hologram by using CPU...
void Wavenumber_output(int &wavenumber)
void absMat(matrix< Complex< T >> &src, matrix< T > &dst)
Function for extracts Complex absolute value.
bool load(const char *real, const char *imag)
Load bmp or bin file.
bool propagationHolo_CPU(float depth)
Function for propagation hologram by using CPU.
bool setFileName(const std::string &_fname)
bool propagationHolo_GPU(float depth)
Function for propagation hologram by using GPU.
XMLError LoadFile(const char *filename)
void linInterp(vector< T > &X, matrix< Complex< T >> &src, vector< T > &Xq, matrix< Complex< T >> &dst)
Linear interpolation.
Real minOfMat(matrix< Real > &src)
Function for extracts minimum of matrix , where matrix is real number.
void focal_length_Set(double red, double green, double blue, double rad)
virtual uchar * loadAsImg(const char *fname)
Function for loading image files.
Real maxOfMat(matrix< Real > &src)
Function for extracts maximum of matrix , where matrix is real number.
void setWavelength(const Real _wavlen, const LenUnit _unit=LenUnit::m)
void setNumOfPixel(const uint _pxNumX, const uint _pxNumY)
void Data_output(uchar *data, int pos, int bitpixel)
void Parameter_Set(int nx, int ny, double width, double height, double NA)
virtual void ophFree(void)
Pure virtual function for override in child classes.
void getOHCheader(oph::ohcHeader &_Header)
double sigGetParamSF_GPU(float zMax, float zMin, int sampN, float th)
Extraction of distance parameter using sharpness functions by using GPU.
void cvtOffaxis_GPU(Real angleX, Real angleY)
void getWavelength(std::vector< double_t > &wavlen_array)
const XMLElement * FirstChildElement(const char *name=0) const
vector< T > linspace(T first, T last, int len)
Generate linearly spaced vector.
double sigGetParamSF_CPU(float zMax, float zMin, int sampN, float th)
Extraction of distance parameter using sharpness functions by using CPU.