Filter Library | Camera | Interface Physics |
00001 /* 00002 * ScanFilterLinearRegression.h - determine linear regression parameters of image. 00003 * 00004 * This file is part of the Camera Filter Library. 00005 * Computer Aided Measurement Environment for Realtime Atomic imaging (Camera) 00006 * 00007 * Copyright (C) 2004-2005, Leiden Probe Microscopy. 00008 * Copyright (C) 2004-2005, Universiteit Leiden. 00009 * 00010 * Authors: Martin J. Moene (original) 00011 * 00012 * $Id: ScanFilterLinearRegression.h 339 2006-02-27 12:02:15Z moene $ 00013 */ 00014 00015 #ifndef CFL_SCANFILTERLINEARREGRESSION_H 00016 #define CFL_SCANFILTERLINEARREGRESSION_H 00017 00018 #if _MSC_VER > 1000 00019 #pragma once 00020 #endif // _MSC_VER > 1000 00021 00022 #include <cfl/ScanFilter.h> // for base class 00023 #include <cfl/ScanBaseBuffer.h> // for ValueType 00024 #include <cfl/ToolCilImage.h> // for Image type and ToImage conversion shim 00025 00026 #include <cil/LinearRegressionImageFilter.h> // for class LinearRegressionImageFilter 00027 00028 /** 00029 * \addtogroup cfl_filterlinearregression Linear Regression Filter 00030 * \brief linear regression filter. 00031 * 00032 00033 <h3>Purpose</h3> 00034 This filter calculates linear regression parameters \f$a\f$, \f$b\f$ and \f$c\f$ 00035 for a small area around each pixel of an image. 00036 00037 <h3>Description</h3> 00038 This filter reveals the angles in x- and y-direction and the offset in the 00039 z-direction at the location of each pixel of an image. 00040 00041 For a small area around each image's pixel, the filter determines the plane of 00042 that area expressed as \f$a x + b y + c\f$. 00043 00044 The filter determines the linear regression parameters \f$a\f$, \f$b\f$ and 00045 \f$c\f$ by subtracting \f$a x + b y + c\f$ from each point \f$Z_{x,y}\f$, 00046 where \f$a\f$, \f$b\f$ and \f$c\f$ are such that the error with respect to 00047 the flat plane is minimalized. 00048 00049 See also \ref cfl_filterbgsplanar . 00050 00051 <h3>Algorithm</h3> 00052 00053 00054 \f[ 00055 (a, b, c)_{y_i,x_i} = \textrm{LinReg}( Z(x_i,y_i), 00056 \textrm{Area}(y_i - \frac{height}{2}, x_i - \frac{width}{2}, 00057 y_i + \frac{height}{2}, x_i + \frac{width}{2} ) ) 00058 \f] 00059 00060 For the pixels of regions that only partly overlap with the image, the value 00061 of the pixel that is nearest to the area's pixel location is used: thus the 00062 value of the pixels at the boundary extend into the border. 00063 00064 \code 00065 k k k 00066 00067 k [k] k i i i i i i 00068 00069 k k k i i i i i i 00070 00071 i i i i i i i i 00072 00073 i i i i i i i i 00074 00075 k: region 00076 i: image 00077 \endcode 00078 00079 \f$\alpha\f$ and \f$\beta\f$ are calculated as follows. 00080 \f{eqnarray*} 00081 \alpha [\pi] & = & \textrm{atan}\ a \\ 00082 \alpha [degrees] & = & \frac{180\ \textrm{atan}\ a}{\pi} 00083 \f} 00084 00085 The linear regression algorithm used is described in a separate booklet 00086 \ref cfl_alg "[CFLALG]". 00087 00088 <h3>Examples</h3> 00089 Try to find some interesting pictures for most filters. 00090 00091 <h3>Contact</h3> 00092 Dipl.phys. M.J. Rost<br> 00093 Huygens Laboratorium<br> 00094 Universiteit Leiden<br> 00095 Niels Bohrweg 2<br> 00096 2333 CA Leiden, The Netherlands<br> 00097 <br> 00098 Tel: +31 71 5275600<br> 00099 Fax: +31 71 5275404<br> 00100 <br> 00101 E-mail: rost@physics.LeidenUniv.nl<br> 00102 Web: http://www.geocities.com/marcel_rost/<br> 00103 00104 * 00105 * @{ 00106 */ 00107 00108 /** 00109 * the linear regression filter type. 00110 */ 00111 typedef cil::Image< CScanBaseBuffer::ValueType > ImageType; 00112 typedef cil::LinearRegressionImageFilter< ImageType > LinearRegressionImageFilter; 00113 //typedef cil::TLinRegFilter<CScanBaseBuffer::ValueType> CLinRegFilter; 00114 00115 DECLARE_CLASS( CScanFilterLinearRegression ); // create various types 00116 00117 /** 00118 * \brief linear regression scanfilter. 00119 * 00120 * 00121 * \author Martin J. Moene 00122 */ 00123 00124 class CScanFilterLinearRegression : public CScanFilter 00125 { 00126 public: 00127 /** 00128 * the value type. 00129 */ 00130 typedef CScanBaseBuffer::ValueType value_type; 00131 00132 /** 00133 * linear regression parameters to select from. 00134 */ 00135 typedef LinearRegressionImageFilter::FeatureSelector FeatureSelector; 00136 00137 /// 00138 /// \name Construction 00139 /// @{ 00140 00141 /** 00142 * default constructor. 00143 */ 00144 CScanFilterLinearRegression(); 00145 00146 /** 00147 * destructor 00148 */ 00149 virtual ~CScanFilterLinearRegression(); 00150 00151 /// @} 00152 /// \name Camera--Filter Interface 00153 /// @{ 00154 00155 // virtual BOOL CanDoPartialData() const; 00156 // virtual BOOL CanDoDialogEntry() const; 00157 00158 /** 00159 * \brief configure filter with settings as provided by the application on the 00160 * filterlist window (e.g. via registry); see also CScanFilterNull::ReadFilterSettings(). 00161 */ 00162 virtual void ReadFilterSettings( ); 00163 00164 /** 00165 * \brief save filter settings e.g. for use with the filterlist window (e.g. via registry); 00166 * see also ReadFilterSettings(). 00167 */ 00168 virtual void WriteFilterSettings( ) const; 00169 00170 /** 00171 * provide current filter parameter(s) for filter-scripting capture 00172 * in the main application; 00173 * see also CScanFilterNull::GetParameters(). 00174 */ 00175 virtual LPCTSTR GetParameters( ) const; 00176 00177 /** 00178 * set parameters for filter-script execution of filter; 00179 * see also CScanFilterNull::SetParameters(). 00180 */ 00181 virtual BOOL SetParameters( LPCTSTR lpParameters ); 00182 00183 /** 00184 * create filter dialog and pre Apply() filter to view result; 00185 * see also CScanFilterNull::RunModeless(). 00186 */ 00187 virtual BOOL RunModeless( CWnd *pParentWnd, CDocument *pDoc ); 00188 00189 /** 00190 * let PreApplyCore() perform the filter pre-processing; catch MFC and std exceptions; 00191 * see also Apply(). 00192 */ 00193 virtual BOOL PreApply(); 00194 00195 /** 00196 * let ApplyCore() perform the filter processing; catch MFC and std exceptions; 00197 * see also CScanFilterNull::Apply(). 00198 */ 00199 virtual BOOL Apply(); 00200 00201 /** 00202 * check parameters, take care of a properly sized output buffer, 00203 * set its name and copy filter parameters; 00204 * see also ApplyCore(). 00205 */ 00206 virtual BOOL PreApplyCore(); 00207 00208 /** 00209 * pre-apply and process; 00210 * see also CScanFilterNull::ApplyCore(). 00211 */ 00212 virtual BOOL ApplyCore(); 00213 00214 /** 00215 * measure algorithm performance. 00216 */ 00217 virtual SPerformanceTestResult 00218 GetPerformanceTestResult(); 00219 00220 /// @} 00221 /// \name Predicates 00222 /// @{ 00223 00224 /// @} 00225 /// \name Accessors 00226 /// @{ 00227 00228 /** 00229 * number of columns in area. 00230 */ 00231 int MaxCols(); 00232 00233 /** 00234 * number of columns in area. 00235 */ 00236 int MaxRows(); 00237 00238 /** 00239 * number of columns in area. 00240 */ 00241 int Ncols(); 00242 00243 /** 00244 * number of rows in area. 00245 */ 00246 int Nrows(); 00247 00248 /** 00249 * number of pixels in area. 00250 */ 00251 int Size(); 00252 00253 /** 00254 * the angle theta for weighted sum of A.cos(theta) + B.sin(theta). 00255 */ 00256 double Theta(); 00257 00258 /** 00259 * the factor to scale Alpha or Beta with. 00260 */ 00261 double Factor(); 00262 00263 /** 00264 * the selected linear regression parameter. 00265 */ 00266 FeatureSelector Parameter(); 00267 00268 /** 00269 * the selected parameter name. 00270 */ 00271 CharCptr ParamName(); 00272 00273 /// @} 00274 /// \name Mutators 00275 /// @{ 00276 00277 /** 00278 * set the number of columns in area. 00279 */ 00280 void Ncols( int ncols ); 00281 00282 /** 00283 * set the number of rows in area. 00284 */ 00285 void Nrows( int nrows ); 00286 00287 /** 00288 * set the angle Theta. 00289 */ 00290 void Theta ( double theta ); 00291 00292 /** 00293 * set the factor to scale Alpha or Beta with. 00294 */ 00295 void Factor( double factor ); 00296 00297 /** 00298 * select the linear regression parameter to output. 00299 */ 00300 void Parameter( FeatureSelector p ); 00301 00302 /// @} 00303 00304 protected: 00305 /** 00306 * store or retrieve the object's settings; 00307 * currently filter serialization is not used; 00308 * see also CScanFilterNull::Serialize(). 00309 */ 00310 virtual void Serialize( CArchive& ar ); 00311 00312 DECLARE_SERIAL( CScanFilterLinearRegression ) 00313 00314 public: 00315 /** 00316 * filter name 00317 */ 00318 static LPCTSTR m_lpcsFilterName; 00319 00320 /** 00321 * the class short filtername. 00322 */ 00323 static LPCTSTR m_lpcsShortFilterName; 00324 00325 /** 00326 * default X and Y 00327 */ 00328 static const int def_iXY; 00329 00330 /** 00331 * default A,B,Alpha,Beta multiplication factor 00332 */ 00333 static const double def_dFactor; 00334 00335 /** 00336 * default selection of parameter 00337 */ 00338 static const FeatureSelector def_eParameter; 00339 00340 private: 00341 /** 00342 * the number of columns to include (must be odd) 00343 */ 00344 int m_iSizeX; 00345 00346 /** 00347 * the number of rows to include (must be odd) 00348 */ 00349 int m_iSizeY; 00350 00351 /** 00352 * angle for weighted sum of A and B 00353 */ 00354 double m_dTheta; 00355 00356 /** 00357 * factor to multiply Alpha or Beta with 00358 */ 00359 double m_dFactor; 00360 00361 /** 00362 * the selected parameter 00363 */ 00364 FeatureSelector m_eParameter; 00365 }; 00366 00367 /// @} group cfl_filterlinearregression 00368 00369 /* 00370 * number of columns in area. 00371 */ 00372 inline int CScanFilterLinearRegression::MaxCols() 00373 { 00374 return m_lpsbIn->Columns(); 00375 } 00376 00377 /* 00378 * number of columns in area. 00379 */ 00380 inline int CScanFilterLinearRegression::MaxRows() 00381 { 00382 return m_lpsbIn->Rows(); 00383 } 00384 00385 /* 00386 * number of columns in area. 00387 */ 00388 inline int CScanFilterLinearRegression::Ncols() 00389 { 00390 return m_iSizeX; 00391 } 00392 00393 /* 00394 * number of rows in area. 00395 */ 00396 inline int CScanFilterLinearRegression::Nrows() 00397 { 00398 return m_iSizeY; 00399 } 00400 00401 /* 00402 * number of pixels in area. 00403 */ 00404 inline int CScanFilterLinearRegression::Size() 00405 { 00406 return Nrows() * Ncols(); 00407 } 00408 00409 /* 00410 * the angle theta for weighted sum of A.cos(theta) + B.sin(theta). 00411 */ 00412 inline double CScanFilterLinearRegression::Theta() 00413 { 00414 return m_dTheta; 00415 } 00416 00417 /* 00418 * the factor to scale Alpha or Beta with. 00419 */ 00420 inline double CScanFilterLinearRegression::Factor() 00421 { 00422 return m_dFactor; 00423 } 00424 00425 /* 00426 * the selected linear regression parameter. 00427 */ 00428 inline CScanFilterLinearRegression::FeatureSelector CScanFilterLinearRegression::Parameter() 00429 { 00430 return m_eParameter; 00431 } 00432 00433 /* 00434 * set the number of columns in area. 00435 */ 00436 inline void CScanFilterLinearRegression::Ncols( int ncols ) 00437 { 00438 m_iSizeX = ncols; 00439 } 00440 00441 /* 00442 * set the number of rows in area. 00443 */ 00444 inline void CScanFilterLinearRegression::Nrows( int nrows ) 00445 { 00446 m_iSizeY = nrows; 00447 } 00448 00449 /* 00450 * set the angle Theta. 00451 */ 00452 inline void CScanFilterLinearRegression::Theta( double theta ) 00453 { 00454 m_dTheta = theta; 00455 } 00456 00457 /* 00458 * set the factor to scale Alpha or Beta with. 00459 */ 00460 inline void CScanFilterLinearRegression::Factor( double factor ) 00461 { 00462 m_dFactor = factor; 00463 } 00464 00465 /* 00466 * select the linear regression parameter to output. 00467 */ 00468 inline void CScanFilterLinearRegression::Parameter( FeatureSelector p ) 00469 { 00470 m_eParameter = p; 00471 } 00472 00473 #endif // #ifndef CFL_SCANFILTERLINEARREGRESSION_H 00474 00475 /* 00476 * end of file 00477 */ 00478