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 14592 2011-03-11 23:19:12Z jshen $ 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 //! Create a mask of an object and transparent pixels in desired area 00173 template <class T_or_RGB> 00174 Image<T_or_RGB> createMask(const Image<T_or_RGB>& fg, 00175 const Image<bool> mask, 00176 const T_or_RGB transparent = T_or_RGB()); 00177 00178 //! Mosaic mapping of transparent pixels of fg into multiple bg's 00179 //! Equivalent to several simultaneous composite operations 00180 template <class T_or_RGB> 00181 Image<T_or_RGB> mosaic(const Image<T_or_RGB>& fg, 00182 const Image<T_or_RGB>* bg, 00183 const T_or_RGB* transvalues, 00184 const uint Nimages); 00185 00186 //! apply a translucent layer (also called alpha blending) 00187 template <class T_or_RGB> 00188 Image<T_or_RGB> alphaBlend(const Image<T_or_RGB>& fg, 00189 const Image<T_or_RGB>& bg, 00190 const double alpha = 0.8, 00191 const T_or_RGB transparent = T_or_RGB()); 00192 00193 //! make a binary version of the source image 00194 /*!@param src source image 00195 @param threshold the threshold used for binarization 00196 @param lowVal value for all points <= threshold 00197 @param highVal value for all points > threshold*/ 00198 template <class T> 00199 Image<byte> makeBinary(const Image<T>& src, 00200 const T& threshold, 00201 const byte lowVal = byte(0), 00202 const byte highVal = byte(255)); 00203 00204 //! make a binary version of the source image 00205 /*!@param src source image 00206 @param highThresh the threshold used for binarization 00207 @param lowThresh the threshold used for binarization 00208 @param lowVal value for all points <= threshold 00209 @param highVal value for all points > threshold*/ 00210 template <class T> 00211 Image<byte> makeBinary2(const Image<T>& src, 00212 const T& lowThresh, 00213 const T& highThresh, 00214 const byte lowVal = byte(0), 00215 const byte highVal = byte(255)); 00216 00217 //! paste foreground into background image at 00218 //! location as the upper-left corner in the background frame 00219 /*!@param transparent pixels with this value are not replaced in background*/ 00220 template <class T_or_RGB> 00221 void pasteImage(Image<T_or_RGB>& background, 00222 const Image<T_or_RGB>& foreground, 00223 const T_or_RGB& transparent, 00224 const Point2D<int> location, 00225 float opacity = 1.0F); 00226 00227 //! Paste a gabor into an image area. Account for overlap 00228 /*! this is a simple extention to paste, but it tests for gabor 00229 overlap and attempts rectify similar to solution for MakeSnake 00230 by taking the pixel value furthest from the background value 00231 @param background This is the color of the image background 00232 */ 00233 template <class T> 00234 void inplacePasteGabor(Image<T>& dst, 00235 const Image<T>& gabor, 00236 const Point2D<int>& pos,const T background); 00237 00238 //! Floods object >= thresh with val from seed and returns area 00239 template <class T> 00240 int flood(const Image<T>& src, 00241 Image<T>& dest, const Point2D<int>& seed, 00242 const T thresh, const T val); 00243 00244 //! How many particles >= thresh ? 00245 template <class T> 00246 int countParticles(const Image<T>& src, const T thresh); 00247 00248 //! Add background noise to image 00249 /*! Range should be max value for any image 00250 of the type to which we add noise */ 00251 template <class T> 00252 void inplaceAddBGnoise(Image<T>& dst, const float range); 00253 00254 //! Add background noise to image 00255 /*! Range should be max value for any image 00256 of the type to which we add noise 00257 similar to addBGnoise, but eliminates BNG.. constant*/ 00258 template <class T> 00259 void inplaceAddBGnoise2(Image<T>& dst, const float range); 00260 00261 // ###################################################################### 00262 // ###################################################################### 00263 /* So things look consistent in everyone's emacs... */ 00264 /* Local Variables: */ 00265 /* indent-tabs-mode: nil */ 00266 /* End: */ 00267 00268 #endif // !IMAGE_TRANSFORMS_H_DEFINED