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.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
25 #define CPEAK
26 
36 #include "CImg_math.h"
37 #include "Cpeak_factory.h"
38 
46 template<typename T>
47 class Cpeak
48 {
49 
50  public:
51 
52  std::string class_name;
53  T m_flag, m_mag; //peak flag, and peak magnitude
54  std::vector<T> m_pos;//peak positions
55  int _3D;//if 3D
56 
57  bool m_verbose;
58 
59 
60  Cpeak(): m_flag(0), m_mag(0)
61  {// constructor
62 
66  class_name = "Cpeak";
67  m_pos.clear();
68 
69  }
70 
71  virtual void exec(CImg<T> &img)
72  {// exec
73 
74  set_peakDim(img);// check for active spatial dimensions
75 
76  peak_detection(img);// detect peak position function of the method used
77 
78  peak_accuracy(img);// peak form accuracy compared to sub_pix peak modeling (flag)
79 
80  peak_delete(img);// only for multi peak detection
81 
82  set_origin(img);// only when peak image come from fft since the origin is shifted
83 
84  }// method exec
85 
86  virtual void peak_detection(CImg<T> &img) = 0;
87 
88  void set_peakDim(CImg<T> &img)
89  {// set_peakDim
90 
91  int dim(2);
92  m_pos.clear();
93 
94  //check for active dimensions
95  if (!img.is_sameZ(1)){dim++;_3D = 1;}
96 
97  for (int i=0; i<dim; i++)
98  {
99  m_pos.push_back(0);
100  }
101 
102 
103  }
104 
105  virtual void peak_accuracy(CImg<T> &img)
106  {
108  m_flag = 0;
109 
110  }
111 
112  virtual void peak_delete(CImg<T> &img)
113  {
122  float sig(15);// patch diameter
124  T depth_0, depth_1;
125 
126  if (_3D){depth_0 = m_pos[2]-sig; depth_1 = m_pos[2]+sig;}else{depth_0 = 0; depth_1 = 0;}
127  img.draw_rectangle(m_pos[0]-sig,m_pos[1]-sig,depth_0,0,m_pos[0]+sig,m_pos[1]+sig,depth_1,0,0,1);
128  //(x0,y0,z0,c0, x1,y1,z1,c1, value, opacity)
129 
130  }
131 
132  void set_origin(CImg<T> &img)
133  {// set_origin
134 
135  //warning peak location detection is done with the zero origin centered within the image, thus the effective location must found throw:
136 
137  m_pos[0] = img.width()/2-m_pos[0];
138  m_pos[1] = img.height()/2-m_pos[1];
139  if (_3D){m_pos[2] = img.depth()/2-m_pos[2];}
140 
141  #ifdef cimg_use_fftw3 //FFtw flip image origin
142  for (int i=0; i<m_pos.size(); i++){m_pos[i] = -m_pos[i];}
143  #endif
144 
145  }
146 
147  std::vector<T> content()
148  {// content
149 
153  std::vector<T> stats;
154  stats.clear();
155 
156  stats.push_back(m_flag);// flag
157  stats.push_back(m_mag);// magnitude of peak for snr calcul
158 
159  for (int i=0; i<m_pos.size(); i++){stats.push_back(m_pos[i]);}//peak location
160 
161  return stats;
162 
163  }
164 
165 };
166 
167 #endif
This class localizes the most important peak within an image, removes it and provide peak statistics...
Definition: Cpeak.h:47
virtual void peak_delete(CImg< T > &img)
Definition: Cpeak.h:112
virtual void peak_accuracy(CImg< T > &img)
Definition: Cpeak.h:105
Cpeak()
Definition: Cpeak.h:60
std::vector< T > content()
Definition: Cpeak.h:147