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];
90 void ophSig::linInterp(vector<T> &X, matrix<Complex<T>> &src, vector<T> &Xq, matrix<Complex<T>> &dst)
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;
208 int wavelength_num =
OHC_decoder->getNumOfWavlen();
229 std::string fullname = fname;
239 OHC_encoder->setFieldEncoding(FldStore::Directly, FldCodeType::RI);
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;
532 for (
int j = 0; j <
ComplexH[0].size[
_Y]; j++) {
533 for (
int i = 0; i <
ComplexH[0].size[
_X]; i++) {
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++)
591 for (
int j = 0; j <
ComplexH[0].size[
_Y]; j++) {
592 for (
int i = 0; i <
ComplexH[0].size[
_X]; i++) {
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;
850 for (
int j = 0; j <
ComplexH[0].size[
_Y]; j++) {
851 for (
int i = 0; i <
ComplexH[0].size[
_X]; i++) {
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++)
883 for (
int j = 0; j <
ComplexH[0].size[
_Y]; j++) {
884 for (
int i = 0; i <
ComplexH[0].size[
_X]; i++) {
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;
930 for (
int j = 0; j <
ComplexH[0].size[
_Y]; j++) {
931 for (
int i = 0; i <
ComplexH[0].size[
_X]; i++) {
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++)
963 for (
int j = 0; j <
ComplexH[0].size[
_Y]; j++) {
964 for (
int i = 0; i <
ComplexH[0].size[
_X]; i++) {
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));
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);
1316 int xshift = nx / 2;
1317 int yshift = ny / 2;
1328 for (i = 0; i < ny; i++)
1330 int ii = (i + yshift) % ny;
1333 for (j = 0; j < nx; j++)
1336 int jj = (j + xshift) % nx;
1337 double temp = FH(jj, ii)[
_RE];
1338 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];
1339 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];
1356 int xshift = nx / 2;
1357 int yshift = ny / 2;
1364 for (i = 0; i < ny; i++)
1366 int ii = (i + yshift) % ny;
1369 for (j = 0; j < nx; j++)
1372 int jj = (j + xshift) % nx;
1373 double temp = FH(jj, ii)[
_RE];
1374 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];
1375 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];
1429 for (i = 0; i < nx; i++)
1431 for (j = 0; j < ny; j++)
1437 Flr(i, j)[
_RE] = (*ComplexH)(i, j)[
_RE];
1438 Fli(i, j)[
_RE] = (*ComplexH)(i, j)[
_IM];
1447 int xshift = nx / 2;
1448 int yshift = ny / 2;
1450 for (i = 0; i < nx; i++)
1452 int ii = (i + xshift) % nx;
1453 for (j = 0; j < ny; j++)
1455 int jj = (j + yshift) % ny;
1456 Hsyn(i, j)[
_RE] = Flr(i, j)[
_RE] * G(i, j);
1457 Hsyn(i, j)[
_IM] = Fli(i, j)[
_RE] * G(i, j);
1463 Fo(ii, jj) = pow(Hsyn(i, j), 2) / (pow(
abs(Hsyn(i, j)), 2) + pow(10, -300));
1469 tn.resize(t.size());
1470 Fon.resize(1, t.size());
1472 int size = (int)tn.size();
1473 for (
int i = 0; i < size; i++)
1475 tn.at(i) = pow(t.at(i), 0.5);
1476 Fon(0, i)[
_RE] = Fo(nx / 2 - 1, nx / 2 - 1 + i)[
_RE];
1482 Ab_yn.resize(yn.size[
_X], yn.size[
_Y]);
1484 Ab_yn_half.resize(1, nx / 4 + 1);
1486 for (
int i = 0; i < nx / 4 + 1; i++)
1488 Ab_yn_half(0, i) = Ab_yn(0, nx / 4 + i - 1)[
_RE];
1489 if (i == 0) max = Ab_yn_half(0, 0);
1492 if (Ab_yn_half(0, i) > max)
1494 max = Ab_yn_half(0, i);
1500 index = -(((index + 1) - 120) / 10) / 140 + 0.1;
1514 Real dz = (zMax - zMin) / sampN;
1525 for (n = 0; n < sampN + 1; n++)
1528 z = ((n)* dz + zMin);
1532 for (i = 0; i < nx - 2; i++)
1534 for (j = 0; j < ny - 2; j++)
1536 ret1 =
abs(I(i + 2, j)[
_RE] - I(i, j)[
_RE]);
1537 ret2 =
abs(I(i, j + 2)[
_RE] - I(i, j)[
_RE]);
1538 if (ret1 >= th) { f += ret1 * ret1; }
1539 else if (ret2 >= th) { f += ret2 * ret2; }
1556 string fname0str = fname0;
1557 string fname90str = fname90;
1558 string fname180str = fname180;
1559 string fname270str = fname270;
1560 int checktype =
static_cast<int>(fname0str.rfind(
"."));
1561 OphRealField f0Mat[3], f90Mat[3], f180Mat[3], f270Mat[3];
1563 std::string f0type = fname0str.substr(checktype + 1, fname0str.size());
1565 uint16_t bitsperpixel;
1569 if (f0type ==
"bmp")
1571 FILE *f0, *f90, *f180, *f270;
1572 f0 = fopen(fname0str.c_str(),
"rb");
1573 f90 = fopen(fname90str.c_str(),
"rb");
1574 f180 = fopen(fname180str.c_str(),
"rb");
1575 f270 = fopen(fname270str.c_str(),
"rb");
1578 LOG(
"bmp file open fail! (phase shift = 0)\n");
1583 LOG(
"bmp file open fail! (phase shift = 90)\n");
1588 LOG(
"bmp file open fail! (phase shift = 180)\n");
1593 LOG(
"bmp file open fail! (phase shift = 270)\n");
1602 LOG(
"bmp header is empty!\n");
1607 LOG(
"check your parameter file!\n");
1612 LOG(
"image size is different!\n");
1664 nRead = fread(f0data,
sizeof(
uchar), size, f0);
1665 nRead = fread(f90data,
sizeof(
uchar), size, f90);
1666 nRead = fread(f180data,
sizeof(
uchar), size, f180);
1667 nRead = fread(f270data,
sizeof(
uchar), size, f270);
1678 for (
int j = 0; j < static_cast<int>(
hInfo.
width); j++)
1683 int idx2 = i * nLine + bpp * j + z;
1684 f0Mat[z](idx, j) = (
double)f0data[idx2];
1685 f90Mat[z](idx, j) = (
double)f90data[idx2];
1686 f180Mat[z](idx, j) = (
double)f180data[idx2];
1687 f270Mat[z](idx, j) = (
double)f270data[idx2];
1691 LOG(
"PSDH file load complete!\n");
1701 LOG(
"wrong type (only BMP supported)\n");
1705 double normalizefactor = 1. / 256.;
1712 ComplexH[z][j][i][
_RE] = (f0Mat[z][j][i] - f180Mat[z][j][i])*normalizefactor;
1713 ComplexH[z][j][i][
_IM] = (f90Mat[z][j][i] - f270Mat[z][j][i])*normalizefactor;
1718 LOG(
"complex field obtained from 4 psdh\n");
1722 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
1724 LOG(
"Implement time : %.5lf sec\n", during_time);
1730 const char* fname0,
const char* fname1,
1731 const char* fname2,
const char* fnameOI,
1732 const char* fnameRI,
int nIter)
1735 string fname0str = fname0;
1736 string fname1str = fname1;
1737 string fname2str = fname2;
1738 string fnameOIstr = fnameOI;
1739 string fnameRIstr = fnameRI;
1740 int checktype =
static_cast<int>(fname0str.rfind(
"."));
1741 OphRealField f0Mat[3], f1Mat[3], f2Mat[3], fOIMat[3], fRIMat[3];
1743 std::string f0type = fname0str.substr(checktype + 1, fname0str.size());
1745 uint16_t bitsperpixel;
1749 if (f0type ==
"bmp")
1751 FILE *f0, *f1, *f2, *fOI, *fRI;
1752 f0 = fopen(fname0str.c_str(),
"rb");
1753 f1 = fopen(fname1str.c_str(),
"rb");
1754 f2 = fopen(fname2str.c_str(),
"rb");
1755 fOI = fopen(fnameOIstr.c_str(),
"rb");
1756 fRI = fopen(fnameRIstr.c_str(),
"rb");
1759 LOG(
"bmp file open fail! (first interference pattern)\n");
1764 LOG(
"bmp file open fail! (second interference pattern)\n");
1769 LOG(
"bmp file open fail! (third interference pattern)\n");
1774 LOG(
"bmp file open fail! (object wave intensity pattern)\n");
1779 LOG(
"bmp file open fail! (reference wave intensity pattern)\n");
1798 LOG(
"bmp header is empty!\n");
1803 LOG(
"check your parameter file!\n");
1808 LOG(
"image size is different!\n");
1868 nRead = fread(f0data,
sizeof(
uchar), size, f0);
1869 nRead = fread(f1data,
sizeof(
uchar), size, f1);
1870 nRead = fread(f2data,
sizeof(
uchar), size, f2);
1871 nRead = fread(fOIdata,
sizeof(
uchar), size, fOI);
1872 nRead = fread(fRIdata,
sizeof(
uchar), size, fRI);
1884 for (
int j = 0; j < static_cast<int>(
hInfo.
width); j++)
1889 size_t idx2 = i * size + bpp * j + z;
1890 f0Mat[z](idx, j) = (
double)f0data[idx2];
1891 f1Mat[z](idx, j) = (
double)f1data[idx2];
1892 f2Mat[z](idx, j) = (
double)f2data[idx2];
1893 fOIMat[z](idx, j) = (
double)fOIdata[idx2];
1894 fRIMat[z](idx, j) = (
double)fRIdata[idx2];
1899 LOG(
"PSDH_3ArbStep file load complete!\n");
1910 LOG(
"wrong type (only BMP supported)\n");
1915 double P[2] = { 0.0, };
1916 double C[2] = { 2.0/
M_PI, 2.0/
M_PI };
1917 double alpha[2] = { 0.0, };
1918 double ps[3] = { 0.0, };
1921 const int nXY = nX * nY;
1926 I01Mat.resize(nY, nX);
1927 I02Mat.resize(nY, nX);
1928 I12Mat.resize(nY, nX);
1929 OAMat.resize(nY, nX);
1930 RAMat.resize(nY, nX);
1932 double sin2m1h, sin2m0h, sin1m0h, sin0p1h, sin0p2h, cos0p1h, cos0p2h, sin1p2h, cos1p2h;
1943 for (
int i = 0; i < nX; i++)
1945 for (
int j = 0; j < nY; j++)
1947 I01Mat[j][i] = (f0Mat[z][j][i] - f1Mat[z][j][i]) / 255.;
1948 I02Mat[j][i] = (f0Mat[z][j][i] - f2Mat[z][j][i]) / 255.;
1949 I12Mat[j][i] = (f1Mat[z][j][i] - f2Mat[z][j][i]) / 255.;
1950 OAMat[j][i] = sqrt(fOIMat[z][j][i] / 255.);
1951 RAMat[j][i] = sqrt(fRIMat[z][j][i] / 255.);
1956 for (
int i = 0; i < nX; i++)
1958 for (
int j = 0; j < nY; j++)
1960 P[0] +=
abs(I01Mat[j][i] / OAMat[j][i] / RAMat[j][i]);
1961 P[1] +=
abs(I12Mat[j][i] / OAMat[j][i] / RAMat[j][i]);
1964 P[0] = P[0] / (4.*((double) nXY));
1965 P[1] = P[1] / (4.*((double) nXY));
1966 LOG(
"P %f %f\n", P[0], P[1]);
1969 for (
int iter = 0; iter < nIter; iter++)
1971 LOG(
"C %d %f %f\n", iter, C[0], C[1]);
1972 LOG(
"ps %d %f %f %f\n", iter, ps[0], ps[1], ps[2]);
1974 alpha[0] = 2.*asin(P[0] / C[0]);
1975 alpha[1] = 2.*asin(P[1] / C[1]);
1978 ps[1] = ps[0] + alpha[0];
1979 ps[2] = ps[1] + alpha[1];
1981 sin2m1h = sin((ps[2] - ps[1]) / 2.);
1982 sin2m0h = sin((ps[2] - ps[0]) / 2.);
1983 sin1m0h = sin((ps[1] - ps[0]) / 2.);
1984 sin0p1h = sin((ps[0] + ps[1]) / 2.);
1985 sin0p2h = sin((ps[0] + ps[2]) / 2.);
1986 cos0p1h = cos((ps[0] + ps[1]) / 2.);
1987 cos0p2h = cos((ps[0] + ps[2]) / 2.);
1988 for (
int i = 0; i < nX; i++)
1990 for (
int j = 0; j < nY; j++)
1992 ComplexH[z][j][i][
_RE] = (1. / (4.*RAMat[j][i]*sin2m1h))*((cos0p1h / sin2m0h)*I02Mat[j][i] - (cos0p2h / sin1m0h)*I01Mat[j][i]);
1993 ComplexH[z][j][i][
_IM] = (1. / (4.*RAMat[j][i]*sin2m1h))*((sin0p1h / sin2m0h)*I02Mat[j][i] - (sin0p2h / sin1m0h)*I01Mat[j][i]);
2000 sin1p2h = sin((ps[1] + ps[2]) / 2.);
2001 cos1p2h = cos((ps[1] + ps[2]) / 2.);
2002 for (
int i = 0; i < nX; i++)
2004 for (
int j = 0; j < nY; j++)
2008 C[0] +=
abs(sinP*cos0p1h - cosP*sin0p1h);
2009 C[1] +=
abs(sinP*cos1p2h - cosP*sin1p2h);
2012 LOG(
"C1 %d %f %f\n", iter, C[0], C[1]);
2013 C[0] = C[0] / ((double)nXY);
2014 C[1] = C[1] / ((double)nXY);
2015 LOG(
"C2 %d %f %f\n", iter, C[0], C[1]);
2018 for (
int i = 0; i < nX; i++)
2020 for (
int j = 0; j < nY; j++)
2030 LOG(
"complex field obtained from 3 interference patterns\n");
2034 auto during_time = ((std::chrono::duration<Real>)(end_time - start_time)).count();
2036 LOG(
"Implement time : %.5lf sec\n", during_time);
bool save(const char *real, const char *imag)
Save data as bmp or bin file.
oph::matrix< Complex< Real > > OphComplexField
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...
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)
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.
bool sigConvertHPO(Real depth, Real_t redRate)
Function for convert complex hologram to horizontal parallax only hologram.
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)
bool sigConvertCAC_GPU(double red, double green, double blue)
Function for Chromatic aberration compensation filter by using GPU.
OphComplexField * ComplexH
oph::matrix< Real > OphRealField
ImgDecoderOhc * OHC_decoder
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 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 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.
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.
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)
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.