00001 /*!@file Image/CutPaste.H Cut+paste operations from/to Image subregions */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Rob Peters <rjpeters@klab.caltech.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/CutPaste.H $ 00035 // $Id: CutPaste.H 14376 2011-01-11 02:44:34Z pez $ 00036 // 00037 00038 #ifndef IMAGE_CUTPASTE_H_DEFINED 00039 #define IMAGE_CUTPASTE_H_DEFINED 00040 00041 #include <vector> 00042 00043 class Dims; 00044 template <class T> class Point2D; 00045 class Rectangle; 00046 template <class T> class Image; 00047 00048 //! Horizontally concatenate two arrays of same height 00049 template <class T_or_RGB> 00050 Image<T_or_RGB> concatX(const Image<T_or_RGB>& left, 00051 const Image<T_or_RGB>& right); 00052 00053 //! Vertically concatenate two arrays of same width 00054 template <class T_or_RGB> 00055 Image<T_or_RGB> concatY(const Image<T_or_RGB>& top, 00056 const Image<T_or_RGB>& bottom); 00057 00058 //! Vertically concatenate topImg and bottomImg 00059 /*! Like concatY(), but doesn't require the two images to have the 00060 same width. */ 00061 template <class T_or_RGB> 00062 Image<T_or_RGB> concatLooseY(const Image<T_or_RGB>& topImg, 00063 const Image<T_or_RGB>& bottomImg, 00064 const T_or_RGB& bgColor = T_or_RGB()); 00065 00066 //! Horizontally concatenate leftImg and rightImg 00067 /*! Like concatX(), but doesn't require the two images to have the 00068 same height. */ 00069 template <class T_or_RGB> 00070 Image<T_or_RGB> concatLooseX(const Image<T_or_RGB>& leftImg, 00071 const Image<T_or_RGB>& rightImg, 00072 const T_or_RGB& bgColor = T_or_RGB()); 00073 00074 //! Extract a subimage from the input image. 00075 /*! The upper left corner of the subimage is given by a Point2D<int>, and the 00076 size of the subimage is given by the Dims. If zerofill is false, then 00077 the rectangle given by Point2D<int>+Dims must be wholly contained within the 00078 bounds of the input image. If zerofill is true, then any output region 00079 that lies outside the bounds of the input will be zero-filled (where 00080 zero means the default value for type T). */ 00081 template <class T_or_RGB> 00082 Image<T_or_RGB> crop(const Image<T_or_RGB>& src, 00083 const Point2D<int>& upperLeft, const Dims& size, 00084 const bool zerofill = false); 00085 00086 //! Overload of crop() using a Rectangle instead of a Point2D<int>+Dims. 00087 template <class T_or_RGB> 00088 Image<T_or_RGB> crop(const Image<T_or_RGB>& src, 00089 const Rectangle& rect, const bool zerofill = false); 00090 00091 //! Shift an image by (int dx, int dy), with horizontal wraparound 00092 template <class T_or_RGB> 00093 Image<T_or_RGB> shift(const Image<T_or_RGB>& srcImg, 00094 const int dx, const int dy); 00095 00096 //! Shift an image by (float dx, float dy) 00097 template <class T_or_RGB> 00098 Image<T_or_RGB> shiftImage(const Image<T_or_RGB>& srcImg, 00099 const float dx, const float dy); 00100 00101 //! Shift an image by (int dx, int dy), without wraparound 00102 template <class T_or_RGB> 00103 Image<T_or_RGB> shiftClean(const Image<T_or_RGB>& srcImg, 00104 const int dx, const int dy, 00105 const T_or_RGB bgval = T_or_RGB()); 00106 00107 //! Paste image into dst at given position 00108 /*! Image must fit within dst and no resizing/interpolation is done. 00109 See embed() for a more sophisticated version with interpolation 00110 and resizing. */ 00111 template <class T_or_RGB> 00112 void inplacePaste(Image<T_or_RGB>& dst, 00113 const Image<T_or_RGB>& img, const Point2D<int>& pos); 00114 00115 //! Set all pixels within a given region to the specified value 00116 /*! Does nothing if the rectangle is invalid. */ 00117 template <class T_or_RGB> 00118 void inplaceClearRegion(Image<T_or_RGB>& dst, 00119 const Rectangle& region, const T_or_RGB& val); 00120 00121 //! Embed image into dst with position & size given in rectangle 00122 template <class T_or_RGB> 00123 void inplaceEmbed(Image<T_or_RGB>& embed, 00124 const Image<T_or_RGB>& img, const Rectangle& r, 00125 const T_or_RGB background, 00126 const bool keep_aspect = true); 00127 00128 //! Find the smallest bounding rectangle around pixels greater than the threshold 00129 template <class T> 00130 Rectangle findBoundingRect(const Image<T>& src, const T threshold); 00131 00132 00133 //! Find the smallest bounding rectangle around the polygon 00134 Rectangle findBoundingRect(const std::vector<Point2D<int> >& poly, const Dims imgDims); 00135 00136 #endif // !IMAGE_CUTPASTE_H_DEFINED 00137 00138 // ###################################################################### 00139 /* So things look consistent in everyone's emacs... */ 00140 /* Local Variables: */ 00141 /* indent-tabs-mode: nil */ 00142 /* End: */