YaDICs  V04.14.a
Yet another Digital Image Correlation software: platform dedicated to 2/3D Fluid and Solid kinematics field measurements.
 All Classes Files Functions Variables Pages
Cpeak_fit.h
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright (C) 2012, The YaDICs Project Developers.
3  * See the COPYRIGHT file at the top-level directory of this distribution ./COPYRIGHT.
4  * See ./COPYING file for copying and redistribution conditions.
5  *
6  * This file is part of YaDICs.
7  * YaDICs is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * YaDICs is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with YaDICs. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Information about how to use the software are provided at http://yadic.univ-lille1.fr/
21  **********************************************************************/
22 
23 
24 #ifndef CPEAK_FIT
25 #define CPEAK_FIT
26 
36 #include "Cpeak_subPix.h"
37 
42 template<typename T, typename Timg>
43 class Cpeak_fit : public Cpeak_subPix<T,Timg>
44 {
45 
46  public:
47 
48  std::string class_name;
49  std::vector<Timg> m_parameters;
50  T m_neighb, m_CornerX, m_CornerY;
51 
52 
53  Cpeak_fit() : Cpeak_subPix<T,Timg>(), m_neighb(20), m_CornerX(0), m_CornerY(0)
54  {// constructor
55 
56  m_parameters.clear();
57 
58  class_name = "Cpeak_fit";
59 
60  }
61 
62  virtual void sub_pixel(CImg<Timg> &img)
63  {// method sub_pixel
64 
78  CImg<Timg> imgC;
79 
80  imgC = img.get_crop(this->m_x0-m_neighb,this->m_y0-m_neighb,this->m_x0+m_neighb,this->m_y0+m_neighb, "false");
81 
82  peak_fit(imgC);
83 
84  set_position();
85 
86  }
87 
88 
89  void ssd(CImg<Timg> &img)
90  {
91 
106  CImg<Timg> n(6,1,1,1,1,0,0,0,0,0), b(1,6,1,1,0);
107  CImg<Timg> nnt(6,6,1,1,0);
108 
109  cimg_forXY(img,x,y){
110 
111  n(1)=x;
112  n(2)=y;
113  n(3)=x*x;
114  n(4)=y*y;
115  n(5)=x*y;
116  nnt+=matrixProduct(n.get_transpose(),n);
117  b+=(n.get_transpose())*img(x,y);
118 
119  };
120 
121  b.solve(nnt);
122 
123  for (int i=0; i<b.height(); i++)
124  {
125 
126  m_parameters.push_back(b(i));
127 
128  };
129 
130  }// method ssd
131 
132  void set_position()
133  {
134 
135  //corner position of the ssd box
136  m_CornerX = this->m_x0-m_neighb;
137  m_CornerY = this->m_y0-m_neighb;
138 
139  //floating position within the box
140  T X1(-2*(m_parameters[1]*m_parameters[4]+m_parameters[2]*m_parameters[5])/(4*m_parameters[3]*m_parameters[4]-m_parameters[5]*m_parameters[5])),
141  Y1((-m_parameters[1]*m_parameters[5]+2*m_parameters[2]*m_parameters[3])/(m_parameters[5]*m_parameters[5]-4*m_parameters[4]*m_parameters[3]));
142 
143  //sub-pixel peak position
144  (*this).m_x0 = m_CornerX+X1;
145  (*this).m_y0 = m_CornerY+Y1;
146 
147  if(m_CornerX<0){m_CornerX=0;};
148  if(m_CornerY<0){m_CornerY=0;};
149 
150  }
151 
152  virtual void peak_fit(CImg<Timg> &img) = 0;
153 
154 };
155 
156 #endif
Definition: Cpeak_fit.h:43
Definition: Cpeak_subPix.h:42
void ssd(CImg< Timg > &img)
Definition: Cpeak_fit.h:89
virtual void sub_pixel(CImg< Timg > &img)
Definition: Cpeak_fit.h:62