24 #ifndef CCORRELATION_OPTICALFLOW_INTEGRATED_BLOCK
25 #define CCORRELATION_OPTICALFLOW_INTEGRATED_BLOCK
42 template<
typename T,
typename Timg>
51 this->class_name =
"Correlation : Optical Flow Integrated per Block";
55 virtual void init(CParameterNetCDF &fp)
64 std::string attribute_name =
"median_filter";
65 int error = fp.loadAttribute(attribute_name,this->m_medianFilter);
66 if (this->m_verbose){printf(
"\t\t median filter over following domain -> %i\n",this->m_medianFilter);}
70 virtual void assignG(
const Cmesh<T,Timg> &oMesh, CImgList<T> &Ke)
74 Ke[0].assign(oMesh.num_mod(),oMesh.num_mod(),1,1, 0);
75 Ke[1].assign(1,oMesh.num_mod(),1,1, 0);
79 virtual void reset(
const int &thread, CImgList<T> &Ke)
93 for (
int dim=0; dim<oMesh.num_var(); dim++)
96 if (this->m_ref[dim] == -1)
99 ref[dim] = oMesh.m_node[dim][oMesh.m_connect[elem].front()]*oImage.m_pix[dim] ;
103 ref[dim] = this->m_ref[dim]*oImage.m_Rpxmm;
110 virtual void evalShape(
const CImg<Timg> &list,
const Cimage<Timg> &oImage,
const Cfield<T,Timg> &oField,
const std::vector<T> &ref,
const std::vector<T> &lCoor,
const std::vector<T> &gCoor, CImgList<T> &N)
113 std::vector<T> coor;coor.assign(3,0);
114 for (
int i=0; i<gCoor.size(); i++)
116 coor[i] = gCoor[i]*oImage.m_pix[i] - ref[i];
119 (oField.m_pShape)->exec(list, coor, N);
123 virtual void tensors(
const int &thread,
const CImgList<T> &Ve,
const T &residue, CImgList<T> &Ke)
126 cimg_forZ(Ke[0], dim)
128 cimg_forX(Ke[0],modi)
130 cimg_forY(Ke[0],modj)
132 Ke[0](modi,modj,dim) += Ve[dim][modi] * Ve[dim][modj];
134 Ke[1](0, modi,dim) += Ve[dim][modi] * residue;
140 virtual void metric(
const Cimage<Timg> &oImage,
const Cmesh<T,Timg> &oMesh, CImgList<T> &solution,
Cfield<T,Timg> &oField, CImgList<T> &N, CImgList<T> &Ve, CImgList<T> &Ke, std::vector<T> &ref, std::vector<T> &offset, std::vector<T> &lCoor, std::vector<T> &gCoor, std::vector<T> &U, std::vector<T> &grad, T &residue, T &deformed, CImg<Timg> &list, CImg<int> &p, CImg<T> ¤t_res)
149 int thread(0), enter(1);
151 #pragma omp for schedule(runtime)
152 cimglist_for(oMesh.m_connect, elem)
155 if (oMesh.cropList(oImage, elem, list, offset))
159 thread = omp_get_thread_num();
162 e_ref(oImage, oMesh, elem, ref);
167 for (
int pix=0; pix<list.size(); pix++)
171 list.contains(list[pix],lCoor[0],lCoor[1],lCoor[2]);
172 for (
int i=0; i<gCoor.size(); i++){gCoor[i]=lCoor[i]+offset[i];}
175 enter = oImage.m_img[0].contains(oImage.m_img[0](gCoor[0],gCoor[1],gCoor[2]));
177 if (!oImage.m_mask.is_empty() and enter){enter = oImage.m_curMask(gCoor[0], gCoor[1], gCoor[2]);}
188 evalShape(list, oImage, oField, ref, lCoor, gCoor, N);
191 this->evalGN(grad,N, Ve);
194 this->evalU(solution, oMesh, elem, N, U);
197 this->
evalRes_loop(oImage, U, gCoor, residue, deformed);
200 current_res[thread] += std::pow(residue,2);
203 tensors(thread, Ve, residue, Ke);
210 cimg_forY(Ke[1],y){solution[y][elem] += Ke[1][y];}
218 oField.m_meanRes.push_back(std::sqrt(current_res.sum())/p.sum()*oImage.m_curImg[0].size()*100/oImage.m_res);
228 this->_3D = oMesh._3D;
232 T previous_res(1e10);
234 CImg<int> p(this->m_threadNB,1,1,1,0);
235 CImgList<T> solution(oField.m_mode);
236 CImg<T> current_res(this->m_threadNB,1,1,1,0);
251 CImgList<T> N(oMesh.num_var(), oMesh.num_mod(),1,1,1, 0);
252 T residue(0), deformed(0);
253 std::vector<T> ref, offset, lCoor, gCoor, grad, U;
254 ref.assign(3,0);offset.assign(3,0);lCoor.assign(3,0); gCoor.assign(3,0); U.assign(3,0); grad.assign(oMesh.num_var(),0);
256 this->assignL(oMesh, Ve);
262 metric(oImage,oMesh,solution,oField,N,Ve,Ke,ref,offset,lCoor,gCoor,U,grad,residue,deformed,list, p,current_res);
266 if (this->m_medianFilter){this->
regularize(oMesh, oImage, solution);}
267 test(solution, this->m_epsilon, oField, previous_res, iter, converged);
273 if (oImage.m_storeActiv)
274 {
Ccorrelation_opticalFlow<T,Timg>::export_res(oImage,oMesh,oField, N,ref,offset,lCoor,gCoor,U,residue,deformed,list);}
281 virtual void store(
Cfield<T,Timg> &oField,
const Cimage<Timg> &oImage,
const std::vector<T> gCoor,
const std::vector<T> &U,
const T &deformed,
const T &residue)
284 if (oImage.m_storeField)
286 cimglist_for(oField.m_field, dim)
290 oField.m_field(dim, gCoor[0],gCoor[1],gCoor[2]) = U[dim];
295 if (oImage.m_storeDef)
299 oField.m_def(gCoor[0],gCoor[1],gCoor[2]) = deformed;
303 if (oImage.m_storeRes)
307 oField.m_res(gCoor[0],gCoor[1],gCoor[2]) = residue;
313 virtual void test(
const CImgList<T> &solution,
const double &epsilon,
Cfield<T,Timg> &oField, T &previous_res,
int &iter,
int &converged)
virtual void regularize(const Cmesh< T, Timg > &oMesh, const Cimage< Timg > &oImage, CImgList< T > &solution)
Definition: Ccorrelation.h:96
virtual void init(CParameterNetCDF &fp)
Definition: Ccorrelation_opticalFlow_integrated.h:56
void evalRes_loop(const Cimage< Timg > &oImage, const std::vector< T > &U, const std::vector< T > &x, T &residue, T &deformed)
Definition: Ccorrelation_opticalFlow.h:209
It implements the Optical Flow with Integrated kinematics within independant block such as Block-matc...
Definition: Ccorrelation_opticalFlow_integrated_block.h:43
Definition: Ccorrelation_opticalFlow_integrated.h:43
It implements optical flow strategy for global shape functions.
This is the mother class of Optical Flow strategies: It implements different steps required for the i...
Definition: Ccorrelation_opticalFlow.h:53
virtual void gradient(const Cimage< Timg > &oImage, const std::vector< T > &x, std::vector< T > &grad)
Definition: Ccorrelation_opticalFlow.h:194
virtual void init(CParameterNetCDF &fp)
Definition: Ccorrelation_opticalFlow_integrated_block.h:55