24 #ifndef CPEAK_BARYCENTER
25 #define CPEAK_BARYCENTER
48 std::string class_name;
53 class_name =
"Cpeak_barycenter";
57 virtual void sub_pixel(CImg<T> &img)
60 std::vector<float> mass;
61 float sum(0), neighb(5);
63 for (
int i=0; i<this->m_pos.size(); i++)
69 switch(this->m_pos.size())
71 case 1: imgC = img.get_crop(this->m_pos[0]-neighb,0,0,0,this->m_pos[0]+neighb,0,0,0,
false);
break;
72 case 2: imgC = img.get_crop(this->m_pos[0]-neighb,this->m_pos[1]-neighb,0,0,this->m_pos[0]+neighb,this->m_pos[1]+neighb,0,0,
false);
break;
73 case 3: imgC = img.get_crop(this->m_pos[0]-neighb,this->m_pos[1]-neighb,this->m_pos[2]-neighb,0,this->m_pos[0]+neighb,this->m_pos[1]+neighb,this->m_pos[2]+neighb,0,
false);
break;
74 case 4: imgC = img.get_crop(this->m_pos[0]-neighb,this->m_pos[1]-neighb,this->m_pos[2]-neighb,this->m_pos[3]-neighb,this->m_pos[0]+neighb,this->m_pos[1]+neighb,this->m_pos[2]+neighb,this->m_pos[3]+neighb,
false);
break;
77 std::cerr<<class_name<<
"::"<<__func__<<
": error: id="<<this->m_pos.size()<<
" is unknown as CImg dimensions\n"<<std::flush;
break;
81 cimg_forXYZC(imgC, x, y, z, c)
83 mass[0]+=imgC(x,y,z,c)*(x-neighb);
84 if(mass.size()>1){mass[1]+=imgC(x,y,z,c)*(y-neighb);}
85 if(mass.size()>2){mass[2]+=imgC(x,y,z,c)*(z-neighb);}
86 if(mass.size()>3){mass[3]+=imgC(x,y,z,c)*(c-neighb);}
91 for (
int i =0; i<this->m_pos.size(); i++)
93 this->m_pos[i] = this->m_pos[i] + mass[i]/sum;
Definition: Cpeak_barycenter.h:43
Definition: Cpeak_subPix.h:42