
00001 /*!@file Image/Transforms.H Transformations on Image 00002 */ 00003 00004 // //////////////////////////////////////////////////////////////////// // 00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00006 // University of Southern California (USC) and the iLab at USC. // 00007 // See http://iLab.usc.edu for information about this project. // 00008 // //////////////////////////////////////////////////////////////////// // 00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00011 // in Visual Environments, and Applications'' by Christof Koch and // 00012 // Laurent Itti, California Institute of Technology, 2001 (patent // 00013 // pending; application number 09/912,225 filed July 23, 2001; see // 00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00015 // //////////////////////////////////////////////////////////////////// // 00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00017 // // 00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00019 // redistribute it and/or modify it under the terms of the GNU General // 00020 // Public License as published by the Free Software Foundation; either // 00021 // version 2 of the License, or (at your option) any later version. // 00022 // // 00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00026 // PURPOSE. See the GNU General Public License for more details. // 00027 // // 00028 // You should have received a copy of the GNU General Public License // 00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00031 // Boston, MA 02111-1307 USA. // 00032 // //////////////////////////////////////////////////////////////////// // 00033 // 00034 // Primary maintainer for this file: Rob Peters <rjpeters@klab.caltech.edu> 00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/Transforms.H $ 00036 // $Id: Transforms.H 11929 2009-11-05 20:59:17Z itti $ 00037 // 00038 00039 #ifndef IMAGE_TRANSFORMS_H_DEFINED 00040 #define IMAGE_TRANSFORMS_H_DEFINED 00041 00042 #include "Util/Promotions.H" 00043 00044 template <class T> class Point2D; 00045 class Dims; 00046 class Rectangle; 00047 template <class T> class Image; 00048 template <class T> class ImageSet; 00049 00050 //! Segment object using an adaptive thresholding & region growing method. 00051 /*! Returns an image that masks the object (see Itti et al, J Neuroimaging, 00052 2001) */ 00053 template <class T> 00054 Image<byte> segmentObject(const Image<T>& src, const Point2D<int>& center); 00055 00056 //! Segment landmark using an adaptive thresholding & region growing method. 00057 /*! Returns an image that masks the landmark 00058 @param activity is a measure of mean activity in the landmark 00059 @param standout is a measure of how much the landmark stands out from 00060 the rest of the image 00061 @param area is the percentage area of landmark 00062 */ 00063 template <class T> 00064 int segmentLandmark(const Image<T>& src, 00065 const Point2D<int>& seed, Image<byte>& target, 00066 double& activity, double& standout, 00067 float& area_percentage); 00068 00069 //! Compute 2D 4-neighbor contours of binary objects in image 00070 /*! Points on the contour will be given value onval, and points not on the contour will have offval. */ 00071 template <class T> 00072 Image<byte> contour2D(const Image<T>& src, const byte onval = 255, const byte offval = 0); 00073 00074 //! 3/4-chamfer distance transform; object = non 0 00075 template <class T> 00076 Image<T> chamfer34(const Image<T>& src, const T dmax = 255); 00077 00078 //! 3/4-chamfer saliency distance transform; object = non 0 00079 //The distance transform (DT) labels each pixel with the distance to the closest 00080 //feature pixel. We have extended this with the salience distance transform 00081 //(Salience DT) by incorporating additional information reflecting the salience 00082 //of the feature pixels. Full details are given in: 00083 // 00084 // P.L. Rosin & G.A.W. West, 00085 // "Salience distance transforms", 00086 // CVGIP: Graphical Models and Image Processing, 00087 // vol 57, no. 6, pp. 483-521, 1995. 00088 00089 template <class T> 00090 Image<T> saliencyChamfer34(const Image<T>& src, const T dmax = 255); 00091 00092 //! Computes 2D discrete cosine transform 00093 /*! of square image patch size*size at offset (offx, offy) */ 00094 template <class T> 00095 Image<typename promote_trait<T, float>::TP> dct(const Image<T>& src, 00096 const int offx, 00097 const int offy, 00098 const int size); 00099 00100 //! FFT-based information measure 00101 template <class T> 00102 float infoFFT(const Image<T>& src, const float eps, const Rectangle& rect); 00103 00104 //! FFT-based information measure 00105 template <class T> 00106 Image<float> infoFFT(const Image<T>& src, const float eps); 00107 00108 //! Examine local maxes in/out of targets and compute a learning weight 00109 /*! Valid ranges for in_thresh and out_thresh are 0..255, plus: use -1 00110 for in_thresh to learn from the background only, or use -1 for 00111 out_thresh to learn from the target only. */ 00112 double learningCoeff(const Image<float>& featureMap, 00113 const Image<byte>& targetDMap, 00114 const bool softmask = false, 00115 const int in_thresh = 20, 00116 const int out_thresh = 255); 00117 00118 //! scale up an image using blocks 00119 template <class T_or_RGB> 00120 Image<T_or_RGB> scaleBlock(const Image<T_or_RGB>& src, const Dims newDims); 00121 00122 //! Floods object >= thresh with val from seed and returns area 00123 /*! a clean version of Image::flood - 00124 problems solved: correct boundary checking, allow for thresh = 0. 00125 @param dest if dest is not initialized, it will be initialized to ZEROS. 00126 ATTENTION: If you want to have the old behavior of dest being initialized 00127 to src, you have to this explicitely before calling floodClean*/ 00128 template <class T> 00129 int floodClean(const Image<T>& src, Image<T>& dest, const Point2D<int>& seed, 00130 const T thresh, const T val, int numdirs = 8); 00131 00132 00133 //! same as floodClean, only finds the bounding box of the region in addition 00134 template <class T> 00135 int floodCleanBB(const Image<T>& src, Image<T>& dest, const Point2D<int>& seed, 00136 const T thresh, const T val, Rectangle& bbox); 00137 00138 //! same as segmentObject, only with floodClean and different parameters 00139 template <class T> 00140 Image<byte> segmentObjectClean(const Image<T>& src, 00141 const Point2D<int>& seed, 00142 int numdirs = 8); 00143 00144 //! degrades a binary image mask s.t. it decays away from the FOA 00145 template <class T> 00146 Image<float> distDegrade(const Image<T>& src, const Point2D<int>& foa, 00147 const float area); 00148 00149 //! set all values >= thresh to val in src and return the result 00150 template <class T> 00151 Image<T> highThresh(const Image<T>& src, const T thresh, const T val); 00152 00153 //! replace all values "from" with "to" and all other values with "other" 00154 template <class T_or_RGB> 00155 Image<T_or_RGB> replaceVals(const Image<T_or_RGB>& src, 00156 const T_or_RGB from, 00157 const T_or_RGB to, 00158 const T_or_RGB other); 00159 00160 //! replace all values "from" with "to" and leave all other values in place 00161 template <class T_or_RGB> 00162 Image<T_or_RGB> replaceVals(const Image<T_or_RGB>& src, 00163 const T_or_RGB from, 00164 const T_or_RGB to); 00165 00166 //! Composite of the non-transparent pixels of fg on top of bg 00167 template <class T_or_RGB> 00168 Image<T_or_RGB> composite(const Image<T_or_RGB>& fg, 00169 const Image<T_or_RGB>& bg, 00170 const T_or_RGB transparent = T_or_RGB()); 00171 00172 //! make a binary version of the source image 00173 /*!@param src source image 00174 @param threshold the threshold used for binarization 00175 @param lowVal value for all points <= threshold 00176 @param highVal value for all points > threshold*/ 00177 template <class T> 00178 Image<byte> makeBinary(const Image<T>& src, 00179 const T& threshold, 00180 const byte lowVal = byte(0), 00181 const byte highVal = byte(255)); 00182 00183 //! make a binary version of the source image 00184 /*!@param src source image 00185 @param highThresh the threshold used for binarization 00186 @param lowThresh the threshold used for binarization 00187 @param lowVal value for all points <= threshold 00188 @param highVal value for all points > threshold*/ 00189 template <class T> 00190 Image<byte> makeBinary2(const Image<T>& src, 00191 const T& lowThresh, 00192 const T& highThresh, 00193 const byte lowVal = byte(0), 00194 const byte highVal = byte(255)); 00195 00196 //! paste foreground into background image at (location) 00197 /*!@param transparent pixels with this value are not replaced in background*/ 00198 template <class T_or_RGB> 00199 void pasteImage(Image<T_or_RGB>& background, 00200 const Image<T_or_RGB>& foreground, 00201 const T_or_RGB& transparent, 00202 const Point2D<int> location, 00203 float opacity = 1.0F); 00204 00205 //! Paste a gabor into an image area. Account for overlap 00206 /*! this is a simple extention to paste, but it tests for gabor 00207 overlap and attempts rectify similar to solution for MakeSnake 00208 by taking the pixel value furthest from the background value 00209 @param background This is the color of the image background 00210 */ 00211 template <class T> 00212 void inplacePasteGabor(Image<T>& dst, 00213 const Image<T>& gabor, 00214 const Point2D<int>& pos,const T background); 00215 00216 //! Floods object >= thresh with val from seed and returns area 00217 template <class T> 00218 int flood(const Image<T>& src, 00219 Image<T>& dest, const Point2D<int>& seed, 00220 const T thresh, const T val); 00221 00222 //! How many particles >= thresh ? 00223 template <class T> 00224 int countParticles(const Image<T>& src, const T thresh); 00225 00226 //! Add background noise to image 00227 /*! Range should be max value for any image 00228 of the type to which we add noise */ 00229 template <class T> 00230 void inplaceAddBGnoise(Image<T>& dst, const float range); 00231 00232 //! Add background noise to image 00233 /*! Range should be max value for any image 00234 of the type to which we add noise 00235 similar to addBGnoise, but eliminates BNG.. constant*/ 00236 template <class T> 00237 void inplaceAddBGnoise2(Image<T>& dst, const float range); 00238 00239 // ###################################################################### 00240 // ###################################################################### 00241 /* So things look consistent in everyone's emacs... */ 00242 /* Local Variables: */ 00243 /* indent-tabs-mode: nil */ 00244 /* End: */ 00245 00246 #endif // !IMAGE_TRANSFORMS_H_DEFINED
1.4.4