24 #ifndef CCORRELATION_INTERCOR
25 #define CCORRELATION_INTERCOR
44 template<
typename T,
typename Timg>
50 std::string m_peak_type;
56 this->class_name =
"Correlation : Intercorrelation";
61 virtual void init(CParameterNetCDF &fp)
68 std::string attribute_name =
"median_filter";
69 int error = fp.loadAttribute(attribute_name,this->m_medianFilter);
70 if (this->m_verbose){printf(
"\t\t median filter over following domain -> %i\n",this->m_medianFilter);}
72 attribute_name =
"peak";
73 error = fp.loadAttribute(attribute_name,m_peak_type);
74 if (this->m_verbose){printf(
"\t\t peak approximation method -> %s\n", m_peak_type.c_str());}
88 pthread_mutex_t fftw_init_mutex;
91 this->_3D = oMesh._3D;
94 T m_meanVal = oImage.m_curImg[0].mean();
95 CImg<T> current_res(this->m_threadNB,1,1,1,0);
96 CImg<int> p(this->m_threadNB,1,1,1,0);
103 std::vector<T> offset;
104 int thread = omp_get_thread_num();
108 CImgList<T> correlogram(2, oMesh.m_win[0], oMesh.m_win[1], oMesh.m_win[2], 1, 0);
109 CImgList<T> F(correlogram), G(correlogram);
112 CNpeak<T> Peaks(m_peak_type, oMesh.grid_dims(3), oMesh.num_var());
113 Peaks.m_verbose = this->m_verbose;
115 #ifdef cimg_use_fftw3 //setup FFTw (thread safe by using mutex)
116 correlogram[0].fftw_assign(F[0],&fftw_init_mutex);
119 #pragma omp for schedule(runtime)
120 cimglist_for(oMesh.m_connect, elem)
123 p[thread]+=oMesh.m_win[0]*oMesh.m_win[1]*oMesh.m_win[2];
125 if (
cropBox(oMesh, oImage, oField, elem, correlogram, offset))
128 if(this->m_verbose and thread == 0)
129 {this->count(elem,oMesh.m_connect.size(),counter);}
131 correl(correlogram, F, G);
133 if(oField.m_storeCorrelo)
135 oField.
m_correlogram.draw_image(offset[0],offset[1],offset[2],0,correlogram[0],1);
138 Peaks.exec(correlogram[0]);
140 actu_field(oImage, oMesh, elem, Peaks, oField);
142 residual(oImage, oMesh, elem, offset, oField, current_res[thread]);
148 #ifdef cimg_use_fftw3
149 correlogram[0].fftw_clear();
150 #endif //cimg_use_fftw3
154 oField.m_meanRes.push_back(std::sqrt(current_res.sum())/p.sum()*oImage.m_curImg[0].size()/oImage.m_res*100);
155 std::cout<<this->class_name.c_str()<<
" -> residue : "<<oField.m_meanRes.back()<<
" \%\n\n";
157 if (this->m_medianFilter)
159 for(
int var=0; var<oMesh.num_var(); var++)
161 oField.m_mode[var+2].blur_median(this->m_medianFilter);
166 if (oImage.m_storeDef or oImage.m_storeRes or oImage.m_storeField)
168 #pragma omp for schedule(runtime)
169 cimglist_for(oMesh.m_connect, elem)
172 if (
cropBox(oMesh, oImage, oField, elem, correlogram, offset))
175 if (oImage.m_storeField){field(oImage, oMesh, elem, offset, oField, current_res[thread]);}
176 if (oImage.m_storeDef){deformField(oImage, oMesh, elem, offset, oField, current_res[thread]);}
177 if (oImage.m_storeRes){residuField(oImage, oMesh, elem, offset, oField, current_res[thread]);}
195 int x(0), y(0), z(0);
196 oField.m_mode[0].contains((oField.m_mode[0])[elem], x,y,z);
198 cimglist_for(oField.m_mode, L)
201 for (
int c=0; c<oMesh.grid_dims(3); ++c)
206 oField.m_mode(L,x,y,z,c) = (floor(oField.m_mode(L,x,y,z,c)/oImage.m_pix[L-2]) + Peaks.m_Nstat(L,0,0,0,c))*oImage.m_pix[L-2];
210 oField.m_mode(L,x,y,z,c) = Peaks.m_Nstat(L,0,0,0,c);
222 std::vector<T> U;U.assign(3,0);
224 for (
int dim=0; dim<oMesh.num_var(); dim++)
226 U[dim] = oField.m_mode[dim+2][elem]/oImage.m_pix[dim];
229 for (
int x=0; x<oMesh.m_win[0]; x++)
231 for (
int y=0; y<oMesh.m_win[1]; y++)
233 for (
int z=0; z<oMesh.m_win[2]; z++)
236 if (oImage.m_curImg[0].contains(oImage.m_curImg(0,offset[0]+x, offset[1]+y, offset[2]+z)))
238 res += std::pow( (T)oImage.m_curImg(0, offset[0]+x, offset[1]+y, offset[2]+z,0) - (T)oImage.m_curImg[1].linear_atXYZ(offset[0]+x+U[0],offset[1]+y+U[1], offset[2]+z+U[2],0, oImage.m_curImg(0, offset[0]+x, offset[1]+y, offset[2]+z,0)) ,2);
250 std::vector<T> U;U.assign(3,0);
252 for (
int dim=0; dim<oMesh.num_var(); dim++)
254 U[dim] = oField.m_mode[dim+2][elem];
257 for (
int x=0; x<oMesh.m_win[0]; x++)
259 for (
int y=0; y<oMesh.m_win[1]; y++)
261 for (
int z=0; z<oMesh.m_win[2]; z++)
263 if (oImage.m_curImg[0].contains(oImage.m_curImg(0,offset[0]+x, offset[1]+y, offset[2]+z)))
265 oField.m_def(offset[0]+x, offset[1]+y, offset[2]+z) = oImage.m_curImg[1].linear_atXYZ(offset[0]+x+U[0]/oImage.m_pix[0],offset[1]+y+U[1]/oImage.m_pix[1], offset[2]+z+U[2]/oImage.m_pix[2],0,oImage.m_curImg(0,offset[0]+x, offset[1]+y, offset[2]+z));
277 std::vector<T> U;U.assign(3,0);
279 for (
int dim=0; dim<oMesh.num_var(); dim++)
281 U[dim] = oField.m_mode[dim+2][elem];
284 for (
int x=0; x<oMesh.m_win[0]; x++)
286 for (
int y=0; y<oMesh.m_win[1]; y++)
288 for (
int z=0; z<oMesh.m_win[2]; z++)
290 if (oImage.m_curImg[0].contains(oImage.m_curImg(0,offset[0]+x, offset[1]+y, offset[2]+z)))
292 oField.m_res(offset[0]+x, offset[1]+y, offset[2]+z) = oImage.m_curImg(0,offset[0]+x, offset[1]+y, offset[2]+z) - oImage.m_curImg[1].linear_atXYZ(offset[0]+x+U[0]/oImage.m_pix[0],offset[1]+y+U[1]/oImage.m_pix[1], offset[2]+z+U[2]/oImage.m_pix[2],0,oImage.m_curImg(0, offset[0]+x, offset[1]+y, offset[2]+z));
303 std::vector<T> U;U.assign(3,0);
305 for (
int dim=0; dim<oMesh.num_var(); dim++)
307 U[dim] = oField.m_mode[dim+2][elem];
310 for (
int x=0; x<oMesh.m_win[0]; x++)
312 for (
int y=0; y<oMesh.m_win[1]; y++)
314 for (
int z=0; z<oMesh.m_win[2]; z++)
317 if (oImage.m_curImg[0].contains(oImage.m_curImg(0,offset[0]+x, offset[1]+y, offset[2]+z)))
319 cimglist_for(oField.m_field, var)
321 oField.m_field(var,offset[0]+x, offset[1]+y, offset[2]+z) = U[var];
337 std::vector<T> coord1;
340 cimglist_for(box,im){box[im].fill(1);}
344 cimglist_for(oMesh.m_node, dim)
346 coord0[dim] = oMesh.m_node[dim][oMesh.m_connect[elem].front()] - oMesh.m_win[dim]/2;
347 coord1[dim] = coord0[dim] + oMesh.m_win[dim] - 1;
350 if (!oImage.m_curMask.is_empty())
351 {box[0].draw_image(0,0,0,0,oImage.m_curMask.get_crop(coord0[0],coord0[1],coord0[2],0,coord1[0],coord1[1],coord1[2],0,0));}
353 if (box[0].mean() > 0.5)
356 std::vector<int> U;U.assign(3,0);
357 cimglist_for(oMesh.m_node, dim)
358 {U[dim] = floor(oField.m_mode[dim + 2][elem]/oImage.m_pix[dim]);}
360 cimg_forXYZ(box[0], x,y,z)
363 if (oImage.m_curImg[0].contains(oImage.m_curImg(0,coord0[0]+x,coord0[1]+y,coord0[2]+z,0)))
364 {box(0, x,y,z) = oImage.m_curImg(0, coord0[0]+x,coord0[1]+y,coord0[2]+z);}
366 {box(0, x,y,z) = this->m_meanVal;}
368 if (oImage.m_curImg[1].contains(oImage.m_curImg(1,coord0[0]+U[0]+x,coord0[1]+U[1]+y,coord0[2]+U[2]+z,0)))
369 {box(1, x,y,z) = oImage.m_curImg(1, coord0[0]+U[0]+x,coord0[1]+U[1]+y,coord0[2]+U[2]+z);}
371 {box(1, x,y,z) = box(0, x,y,z);}
385 virtual void correl(CImgList<T> &correlogram, CImgList<T> &F, CImgList<T> &G) = 0;
388 void FFT(CImgList<T> &correlogram, CImgList<T> &F, CImgList<T> &G)
391 correlogram[0].FFT(F[0],F[1]);
392 correlogram[0].FFT(G[0],G[1]);
396 void iFFT(CImgList<T> &correlogram)
399 correlogram[0].FFT(correlogram[0],correlogram[1],
true);
403 void shift(CImgList<T> &correlogram)
406 std::vector<float> offset;
409 offset[0] = (float)correlogram[0].width()/2;
410 offset[1] = (float)correlogram[0].height()/2;
411 if(this->_3D){offset[2] = (float)correlogram[0].depth()/2;}
413 cimglist_for(correlogram,L)
415 correlogram[L].shift(offset[0],offset[1],offset[2],offset[3],2);
420 virtual void interCor(CImgList<T> &correlogram, CImgList<T> &F, CImgList<T> &G)
423 cimg_forXYZ(correlogram[0],x,y,z)
425 correlogram(0,x,y,z) = F(0,x,y,z)*G(0,x,y,z) + F(1,x,y,z)*G(1,x,y,z);
426 correlogram(1,x,y,z) = F(1,x,y,z)*G(0,x,y,z) - F(0,x,y,z)*G(1,x,y,z);
431 void mean(CImgList<T> &correlogram)
434 T mean0(correlogram[0].mean()), mean1(correlogram[1].mean());
436 correlogram[0]-=mean0;
437 correlogram[1]-=mean1;
void actu_field(const Cimage< Timg > &oImage, const Cmesh< T, Timg > &oMesh, const int &elem, const CNpeak< T > &Peaks, Cfield< T, Timg > &oField)
Definition: Ccorrelation_intercor.h:188
virtual void exec(const Cimage< Timg > &oImage, const Cmesh< T, Timg > &oMesh, Cfield< T, Timg > &oField)
Definition: Ccorrelation_intercor.h:78
this is the mother class of every correlation classes. m_correl_type refers to the the type of correl...
Definition: Ccorrelation.h:65
CImg< T > m_correlogram
to improve, they shouldn't be here//
Definition: Cfield.h:74
virtual void init(CParameterNetCDF &fp)
Definition: Ccorrelation_intercor.h:61
int cropBox(const Cmesh< T, Timg > &oMesh, const Cimage< Timg > &oImage, const Cfield< T, Timg > &oField, const int &elem, CImgList< T > &box, std::vector< T > &coord0)
Definition: Ccorrelation_intercor.h:330
this class implement 7 functions:
Definition: Ccorrelation_intercor.h:45