25 if (imgOutput)
delete[] imgOutput;
26 if (imgRGB)
delete[] imgRGB;
27 if (imgDepth)
delete[] imgDepth;
33 if ((!imgRGB && m_config.num_of_depth == 1) || (!imgRGB && !imgDepth))
40 const uint nWave = context_.waveNum;
41 const int pnX = context_.pixel_number[
_X];
42 const int pnY = context_.pixel_number[
_Y];
43 const Real ppX = context_.pixel_pitch[
_X];
44 const Real ppY = context_.pixel_pitch[
_Y];
45 const long long int pnXY = pnX * pnY;
46 const Real ssX = context_.ss[
_X];
47 const Real ssY = context_.ss[
_Y];
48 const Real nDepth = m_config.num_of_depth;
49 Real nearDepth = m_config.near_depthmap;
50 Real farDepth = m_config.far_depthmap;
51 int nIteration = m_config.num_of_iteration;
55 for (
uint i = 0; i < nWave; i++) {
56 waveRatio[i] = context_.wave_length[nWave - 1] / context_.wave_length[i];
60 Real d = (nDepth == 1) ? 0.0 : (farDepth - nearDepth) / (nDepth - 1);
63 uchar m = getMax(imgDepth, pnX, pnY);
65 memset(depth_quant, 0,
sizeof(
Real) * pnXY);
67 for (
int depth = nDepth; depth > 0; depth--) {
69 #pragma omp parallel for 71 for (
int i = 0; i < pnXY; i++) {
72 depth_quant[i] += (imgDepth[i] > (depth*
m / nDepth)) ? 1 : 0;
80 for (
int depth = 0; depth < nDepth; depth++) {
81 z = farDepth - (d*depth);
83 for (
uint ch = 0; ch < nWave; ch++) {
85 separateColor(ch, pnX, pnY, imgRGB, img);
87 #pragma omp parallel for 89 for (
int i = 0; i < pnXY; i++) {
90 Real val = (depth_quant[i] == depth) ? 1.0 : 0.0;
91 img[i] = val * (
Real)img[i];
93 Real lambda = context_.wave_length[ch];
95 Real hssX = lambda * z / ppX;
96 Real hssY = lambda * z / ppY;
97 Real hppX = hssX / pnX;
98 Real hppY = hssY / pnY;
100 Real hStartX = -hssX / 2;
101 Real hStartY = -hssY / 2;
102 Real startX = -ssX / 2;
103 Real startY = -ssY / 2;
108 uchar *img_tmp =
nullptr;
109 uchar *imgScaled =
nullptr;
114 int scaleX = round(pnX * 4 * waveRatio[ch]);
115 int scaleY = round(pnY * 4 * waveRatio[ch]);
119 img_tmp =
new uchar[ww * hh];
120 imgScaled =
new uchar[scaleX * scaleY];
121 imgScaleBilinear(img, imgScaled, pnX, pnY, scaleX, scaleY);
126 memset(img_tmp, 0,
sizeof(
uchar) * ww * hh);
128 int h1 = round((hh - scaleY) / 2);
129 int w1 = round((ww - scaleX) / 2);
133 #pragma omp parallel for 135 for (
int y = 0; y < scaleY; y++) {
136 for (
int x = 0; x < scaleX; x++) {
137 img_tmp[(y + h1)*ww + x + w1] = imgScaled[y*scaleX + x];
140 img =
new uchar[pnXY];
141 imgScaleBilinear(img_tmp, img, ww, hh, pnX, pnY);
149 #pragma omp parallel for 151 for (
int y = 0; y < pnY; y++) {
152 int offset = y * pnX;
154 Real ty = hStartY + (y * hppY);
155 Real yy = startY + (y * ppY);
157 for (
int x = 0; x < pnX; x++) {
158 target[offset + x] = (
Real)img[offset + x];
161 ran =
rand(0.0, 1.0);
163 ran = ((
Real)
rand() / RAND_MAX) * 1.0;
167 tmp(0.0, ran * 2 *
M_PI);
173 Real tx = hStartX + (x * hppX);
174 Real txy = tx * tx + ty * ty;
175 Real xx = startX + (x * ppX);
176 Real xy = xx * xx + yy * yy;
179 kernel[offset + x] = c1 * t;
180 kernel2[offset + x] = (c3 * xy).exp();
181 result1[offset + x] = target[offset + x] * c4;
182 result1[offset + x] *= kernel[offset + x];
189 fftShift(pnX, pnY, result1, tmp);
191 fftExecute(tmp,
true);
194 if (nIteration == 0) {
196 #pragma omp parallel for 198 for (
int j = 0; j < pnXY; j++) {
199 result2[j] = tmp[j] / kernel2[j];
200 complex_H[ch][j] += result2[j];
205 #pragma omp parallel for 207 for (
int y = 0; y < pnXY; y++) {
208 result2[y] = tmp[y] / kernel2[y];
213 for (
int i = 0; i < nIteration; i++) {
214 for (
int j = 0; j < pnXY; j++) {
215 result2[j] = tmp[j] / kernel2[j];
218 result1[j] = tmp[j].
exp() * kernel2[j];
225 fftShift(pnX, pnY, tmp, result1);
227 for (
int j = 0; j < pnXY; j++) {
228 result1[j] /= kernel[j];
231 result2[j] = (target[j] / 255.0) * aa;
232 result2[j] *= kernel[j];
234 fftShift(pnX, pnY, result2, tmp);
236 fftExecute(tmp2,
true);
238 for (
int j = 0; j < pnXY; j++) {
239 result2[j] = tmp2[j] / kernel2[j];
241 LOG(
"Iteration (%d / %d)\n", i + 1, nIteration);
243 memset(img, 0, pnXY);
244 for (
int j = 0; j < pnXY; j++) {
245 complex_H[ch][j] += result2[j];
248 m_nProgress = (int)((
Real)(depth*nWave + ch) * 100 / ((
Real)nDepth * nWave));
265 delete[] depth_quant;
268 LOG(
"\nTotal Elapsed Time : %lf(s)\n\n",
ELAPSED_TIME(begin, end));
274 const uint nWave = context_.waveNum;
275 const uint pnX = context_.pixel_number[
_X];
276 const uint pnY = context_.pixel_number[
_Y];
277 const long long int pnXY = pnX * pnY;
280 for (
uint ch = 0; ch < nWave; ch++) {
281 for (
int i = 0; i < pnXY; i++) {
282 m_lpNormalized[ch][i] = m_lpEncoded[ch][i] / pi2 * 255;
291 const uint pnX = context_.pixel_number[
_X];
292 const uint pnY = context_.pixel_number[
_Y];
293 const uint nChannel = context_.waveNum;
296 for (
uint ch = 0; ch < nChannel; ch++) {
297 fft2(context_.pixel_number, complex_H[ch],
OPH_BACKWARD);
319 if (!checkExtension(fname,
".xml"))
321 LOG(
"file's extension is not 'xml'\n");
326 LOG(
"Failed to load file \"%s\"\n", fname);
334 if (!next ||
XML_SUCCESS != next->QueryIntText(&m_config.num_of_depth))
335 m_config.num_of_depth = 1;
337 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&m_config.near_depthmap))
340 if (!next ||
XML_SUCCESS != next->QueryDoubleText(&m_config.far_depthmap))
343 if (!next ||
XML_SUCCESS != next->QueryIntText(&m_config.num_of_iteration))
344 m_config.num_of_iteration = 1;
356 const uint pnX = context_.pixel_number[
_X];
357 const uint pnY = context_.pixel_number[
_Y];
358 uchar *imgIFTA =
nullptr;
360 if (imgIFTA !=
nullptr) {
364 uchar *imgTmp = loadAsImg(fname);
367 imgScaleBilinear(imgTmp, imgIFTA, width, height, pnX, pnY,
bytesperpixel);
371 if (bRGB) imgRGB = imgIFTA;
372 else imgDepth = imgIFTA;
379 const long long int size = width * height;
382 for (
int i = 0; i < size; i++) {
383 if (*(src + i) > max) max = *(src + i);
uchar getMax(uchar *src, int width, int height)
structure for 2-dimensional integer vector and its arithmetic.
bool readConfig(const char *fname)
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
#define ELAPSED_TIME(x, y)
bool readImage(const char *fname, bool bRGB)
bool readConfig(const char *fname)
load to configuration file.
XMLError LoadFile(const char *filename)
Real rand(const Real min, const Real max, oph::ulong _SEED_VALUE=0)
Get random Real value from min to max.
void angle(const std::vector< Complex< T >> &src, std::vector< T > &dst)
const XMLElement * FirstChildElement(const char *name=0) const