00001 /*---------------------------------------------------------------------+ 00002 | Library QgarLib, graphics analysis and recognition | 00003 | Copyright (C) 2002 Qgar Project, LORIA | 00004 | | 00005 | This library is free software; you can redistribute it and/or | 00006 | modify it under the terms of the GNU Lesser General Public | 00007 | License version 2.1, as published by the Free Software Foundation. | 00008 | | 00009 | This library is distributed in the hope that it will be useful, | 00010 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00011 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 00012 | See the GNU Lesser General Public License for more details. | 00013 | | 00014 | The GNU Lesser General Public License is included in the file | 00015 | LICENSE.LGPL, in the root directory of the Qgar packaging. See | 00016 | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. | 00017 | To receive a paper copy, write to the Free Software Foundation, | 00018 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 00019 | | 00020 | Contact Project Qgar for any information: | 00021 | LORIA - équipe Qgar | 00022 | B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France | 00023 | email: qgar-contact@loria.fr | 00024 | http://www.qgar.org/ | 00025 *---------------------------------------------------------------------*/ 00026 00027 00028 #ifndef __ABSTRACTGRADIENTIMAGE_H_INCLUDED__ 00029 #define __ABSTRACTGRADIENTIMAGE_H_INCLUDED__ 00030 00031 00032 /** 00033 * @file AbstractGradientImage.H 00034 * @brief Header file of class qgar::AbstractGradientImage. 00035 * 00036 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a> 00037 * @date July 3, 2001 10:12 00038 * @since Qgar 1.0 00039 */ 00040 00041 00042 // For RCS/CVS use: Do not delete 00043 /* $Id: AbstractGradientImage.H,v 1.12 2005/10/14 17:05:45 masini Exp $ */ 00044 00045 00046 00047 // STL 00048 #include <cmath> 00049 // QGAR 00050 #include <qgarlib/AbstractMultiImage.H> 00051 #include <qgarlib/GenImage.H> 00052 00053 00054 00055 namespace qgar 00056 { 00057 00058 00059 /** 00060 * @ingroup IMGPROC_GRAD 00061 * 00062 * @class AbstractGradientImage AbstractGradientImage.H "qgarlib/AbstractGradientImage.H" 00063 * 00064 * @brief Base class to define gradient images. 00065 * 00066 * A pixel of such an image represents a gradient value, 00067 * i.e. a pair of floats corresponding to derivatives in x and y 00068 * directions. 00069 * 00070 * @warning This is an abstract class. It cannot be instantiated. 00071 * 00072 * @see qgar::LocalGradientMaxima 00073 */ 00074 class AbstractGradientImage 00075 00076 : public AbstractMultiImage 00077 00078 { 00079 // ------------------------------------------------------------------- 00080 // T Y P E D E F I N I T I O N S 00081 // ------------------------------------------------------------------- 00082 public: 00083 00084 00085 /** @name Types */ 00086 // ===== 00087 //@{ 00088 00089 /** 00090 * @brief Type of the elements stored in the pixmaps. 00091 */ 00092 typedef float value_type; 00093 00094 /** 00095 * @brief Reference to qgar::AbstractGradientImage::value_type. 00096 */ 00097 typedef value_type& reference; 00098 00099 /** 00100 * @brief Constant reference to qgar::AbstractGradientImage::value_type. 00101 */ 00102 typedef const value_type& const_reference; 00103 00104 /** 00105 * @brief Pointer to qgar::AbstractGradientImage::value_type. 00106 */ 00107 typedef value_type* pointer; 00108 00109 /** 00110 * @brief Constant pointer to qgar::AbstractGradientImage::value_type. 00111 */ 00112 typedef const value_type* const_pointer; 00113 00114 //@} 00115 00116 00117 // ------------------------------------------------------------------- 00118 // P U B L I C M E M B E R S 00119 // ------------------------------------------------------------------- 00120 public: 00121 00122 /** @name Destructor */ 00123 // ========== 00124 //@{ 00125 00126 /** 00127 * @brief Virtual destructor. 00128 */ 00129 virtual ~AbstractGradientImage() 00130 { 00131 // VOID 00132 } 00133 00134 //@} 00135 00136 00137 /** @name Access */ 00138 // ====== 00139 //@{ 00140 00141 /** 00142 * @brief Get copy of x derivatives image. 00143 */ 00144 inline FloatImage dxImg() const; 00145 00146 /** 00147 * @brief Get image of x derivatives. 00148 */ 00149 inline const FloatImage& accessDxImg() const; 00150 00151 /** 00152 * @brief Get copy of y derivatives image. 00153 */ 00154 inline FloatImage dyImg() const; 00155 00156 /** 00157 * @brief Get copy of y derivatives image. 00158 */ 00159 inline const FloatImage& accessDyImg() const; 00160 00161 /** 00162 * @brief Get x derivative value of a pixel. 00163 * @param aX X coordinate (column index) of the pixel 00164 * @param aY Y coordinate (row index) of the pixel 00165 */ 00166 inline float dxPixel(int aX, int aY) const; 00167 00168 /** 00169 * @brief Get y derivative value of a pixel. 00170 * @param aX X coordinate (column index) of the pixel 00171 * @param aY Y coordinate (row index) of the pixel 00172 */ 00173 inline float dyPixel(int aX, int aY) const; 00174 00175 /** 00176 * @brief Get the gradient module of a pixel. 00177 * @param aX X coordinate (column index) of the pixel 00178 * @param aY Y coordinate (row index) of the pixel 00179 */ 00180 inline float gradientModule(int aX, int aY) const; 00181 00182 //@} 00183 00184 00185 /** @name Operators */ 00186 // ========= 00187 //@{ 00188 00189 /** 00190 * @brief Assignment (same as copy constructor). 00191 * 00192 * The current image is not supposed to initially have the same 00193 * dimensions as the given image. 00194 * 00195 * @param anImg image to assign to the current image 00196 * 00197 * @warning Perform a <b>deep copy</b>: The x and y <b>pixel maps</b> 00198 * of the deritave images (qgar::AbstractGradientImage::_dxImg and 00199 * qgar::AbstractGradientImage::_dyImg) of the given image are 00200 * duplicated. 00201 */ 00202 AbstractGradientImage& operator=(const AbstractGradientImage& anImg); 00203 00204 //@} 00205 00206 00207 /** @name Copy the current image */ 00208 // ====================== 00209 //@{ 00210 /** 00211 * @brief Shallow copy: The x and y <b>pixel maps</b> of the deritave 00212 * images (qgar::AbstractGradientImage::_dxImg and 00213 * qgar::AbstractGradientImage::_dyImg) of the given image are 00214 * <b>not duplicated</b>. 00215 * 00216 * @see qgar::AbstractGradientImage::operator= and copy constructor. 00217 * 00218 * @warning When the copy is completed, the x and y <b>pixel maps</b> 00219 * of the deritave images of the new image share their memory space 00220 * with the pixel maps of the current image. 00221 */ 00222 inline AbstractGradientImage shallowCopy(); 00223 //@} 00224 00225 // ------------------------------------------------------------------- 00226 // P R O T E C T E D M E M B E R S 00227 // ------------------------------------------------------------------- 00228 protected: 00229 00230 00231 // ============================================ 00232 /** @name Constructors 00233 Constructors belong to the protected section 00234 so that the class cannot be instantiated. 00235 */ 00236 // ============================================ 00237 //@{ 00238 00239 /** 00240 * @brief Default constructor. 00241 */ 00242 AbstractGradientImage(); 00243 00244 /** 00245 * @brief Copy constructor: Initialize from given gradient image. 00246 * 00247 * @param anImg image to be copied 00248 * 00249 * @warning Perform a <b>deep copy</b>: The x and y deritave 00250 * images of the given multi-layered image are duplicated. 00251 */ 00252 AbstractGradientImage(const AbstractGradientImage& anImg); 00253 00254 /** 00255 * @brief Initialize from given grey-level image. 00256 * 00257 * @param anImg image to be copied into the x and y 00258 * derivative pixel maps 00259 */ 00260 AbstractGradientImage(const GreyLevelImage& anImg); 00261 00262 /** 00263 * @brief Initialize from given float image. 00264 * @param anImg image to be copied into the x and y 00265 * derivative pixel maps 00266 */ 00267 AbstractGradientImage(const FloatImage& anImg); 00268 00269 /** 00270 * @brief Initialize from given double image. 00271 * 00272 * @param anImg image to be copied into the x and y 00273 * derivative pixel maps 00274 */ 00275 AbstractGradientImage(const DoubleImage& anImg); 00276 00277 /** 00278 * @brief Initialize using given width and height. 00279 * 00280 * @param aWidth width of the image 00281 * @param aHeight height of the image 00282 */ 00283 AbstractGradientImage(int aWidth, int aHeight); 00284 00285 /** 00286 * @brief Initialize from all data. 00287 * 00288 * @param aWidth width of the image 00289 * @param aHeight height of the image 00290 * @param aDxImg image of X derivatives 00291 * @param aDyImg image of Y derivatives 00292 */ 00293 AbstractGradientImage(int aWidth, 00294 int aHeight, 00295 FloatImage aDxImg, 00296 FloatImage aDyImg); 00297 00298 //@} 00299 00300 00301 /** @name Representation of a gradient image */ 00302 // ================================== 00303 //@{ 00304 00305 /** 00306 * @brief Image of x derivatives. 00307 */ 00308 FloatImage _dxImg; 00309 /** 00310 * @brief Image of y derivatives. 00311 */ 00312 FloatImage _dyImg; 00313 00314 //@} 00315 00316 // ------------------------------------------------------------------- 00317 }; // class AbstractGradientImage 00318 00319 00320 00321 00322 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00323 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00324 // I N L I N E F U N C T I O N S I M P L E M E N T A T I O N 00325 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00326 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00327 00328 // ====== 00329 // ACCESS 00330 // ====== 00331 00332 // Get copy of x derivatives image 00333 inline FloatImage AbstractGradientImage::dxImg() const 00334 { 00335 return _dxImg; 00336 } 00337 00338 // Get x derivatives image 00339 inline const FloatImage& AbstractGradientImage::accessDxImg() const 00340 { 00341 return _dxImg; 00342 } 00343 00344 // Get copy of y derivatives image 00345 inline FloatImage AbstractGradientImage::dyImg() const 00346 { 00347 return _dyImg; 00348 } 00349 00350 // Get y derivatives image 00351 inline const FloatImage& AbstractGradientImage::accessDyImg() const 00352 { 00353 return _dyImg; 00354 } 00355 00356 // Get x derivative value of a pixel 00357 inline float AbstractGradientImage::dxPixel(int aX, int aY) const 00358 { 00359 return _dxImg.pixel(aX, aY); 00360 } 00361 00362 // Get y derivative value of a pixel 00363 inline float AbstractGradientImage::dyPixel(int aX, int aY) const 00364 { 00365 return _dyImg.pixel(aX, aY); 00366 } 00367 00368 // Get the gradient module of a pixel 00369 inline float AbstractGradientImage::gradientModule(int aX, int aY) const 00370 { 00371 return (float) 00372 hypot((double) dxPixel(aX,aY), (double) dyPixel(aX,aY)); 00373 } 00374 00375 // ==== 00376 // COPY 00377 // ==== 00378 00379 // Shallow copy: The x and y pixel maps of the deritave images 00380 // of the current image are not duplicated 00381 inline AbstractGradientImage AbstractGradientImage::shallowCopy() 00382 { 00383 return AbstractGradientImage(_width, 00384 _height, 00385 _dxImg.shallowCopy(), 00386 _dyImg.shallowCopy()); 00387 } 00388 00389 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00390 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00391 00392 00393 } // namespace qgar 00394 00395 00396 #endif /* __ABSTRACTGRADIENTIMAGE_H_INCLUDED__ */