Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DrawOps.H

Go to the documentation of this file.
00001 /*!@file Image/DrawOps.H functions for drawing on images
00002  */
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2002   //
00005 // by the 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; filed July 23, 2001, following provisional applications     //
00013 // No. 60/274,674 filed March 8, 2001 and 60/288,724 filed May 4, 2001).//
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: Dirk Walther <walther@caltech.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/DrawOps.H $
00035 // $Id: DrawOps.H 11936 2009-11-06 18:05:48Z itti $
00036 //
00037 
00038 #ifndef IMAGE_DRAWOPS_H_DEFINED
00039 #define IMAGE_DRAWOPS_H_DEFINED
00040 
00041 #include "Util/Types.H"
00042 #include "Image/SimpleFont.H"
00043 #include "Image/Pixels.H"
00044 
00045 #include <string>
00046 #include <vector>
00047 
00048 template <class T> class Point2D;
00049 class Dims;
00050 class Rectangle;
00051 template <class T> class Image;
00052 template <class T> class PixRGB;
00053 class ColorMap;
00054 
00055 //! draw the trajectory for the points in foas onto img
00056 /*! Yellow circles and red arrows are drawn, connecting the points in foas.
00057   @param foas a vector with the foci of attention ised for drawing*/
00058 void drawTraj(Image< PixRGB<byte> >& img,
00059               const Point2D<int>* foas_begin, const Point2D<int>* foas_end);
00060 
00061 //! build a combo between a color and greyscale image
00062 /*! @param colimg the color image (e.g., trajectory)
00063    @param bwimg the greyscale image (e.g., saliency map)
00064    @param xcombo will combine horizontally if true, otherwise vertically
00065    @param interp use bilinear interpolation for any image rescaling */
00066 Image< PixRGB<byte> > colGreyCombo(const Image< PixRGB<byte> >& colimg,
00067                                    const Image<float>& bwimg,
00068                                    const bool xcombo,
00069                                    const bool interp = true);
00070 
00071 //! build a combo between a color and color image
00072 /*! @param colimg1 the color image (e.g., trajectory + saliency map)
00073    @param colimg2 the second color image (e.g., the scene highlighted by TRM)
00074    @param xcombo will combine horizontally if true, otherwise vertically
00075    @param interp use bilinear interpolation for any image rescaling */
00076 Image< PixRGB<byte> > colColCombo(const Image< PixRGB<byte> >& colimg1,
00077                                    const Image< PixRGB<byte> >& colimg2,
00078                                   const bool xcombo,
00079                                   const bool interp = true);
00080 
00081 //! highlight an image in the regions given by a mask
00082 Image< PixRGB<byte> > highlightRegions(const Image< PixRGB<byte> >& img,
00083                                        const Image<byte>& mask,
00084                                        const int maxval = 320);
00085 
00086 //! warp image onto height map
00087 Image< PixRGB<byte> > warp3Dmap(const Image< PixRGB<byte> >& img,
00088                                 const Image<float>& hmap,
00089                                 const float pitch, const float yaw,
00090                                 Dims& imdims);
00091 
00092 //! Set values at all locations where mask is non-zero
00093 void inplaceSetValMask(Image<float>& dest,
00094                        const Image<byte>& mask, const float val);
00095 
00096 
00097 //! Draws a disk with color "value" in image
00098 template <class T_or_RGB>
00099 void drawDisk(Image<T_or_RGB>& dst,
00100               const Point2D<int>& center, const int radius,
00101               const T_or_RGB value);
00102 
00103 //! Draw a line from p1 to p2 of color col and pixel radius rad
00104 template <class T_or_RGB>
00105 void drawLine(Image<T_or_RGB>& dst,
00106               const Point2D<int>& p1, const Point2D<int>& p2, const T_or_RGB col,
00107               const int rad = 1);
00108 
00109 //! Draw a line at pos angle ori(rad) and length len
00110 template <class T_or_RGB>
00111 void drawLine(Image<T_or_RGB>& dst,
00112               const Point2D<int>& pos, float ori, float len, const T_or_RGB col,
00113               const int rad = 1);
00114 
00115 //! Draw a corner at pos and ori with an ang
00116 template <class T_or_RGB>
00117 void drawCorner(Image<T_or_RGB>& dst,
00118               const Point2D<int>& pos, float ori, float ang, float len,
00119               const T_or_RGB col, const int rad = 1);
00120 
00121 
00122 //! Draw a rectangle of color col and line width of rad*2, with rounded corners
00123 template <class T_or_RGB>
00124 void drawRect(Image<T_or_RGB>& dst,
00125               const Rectangle& rect, const T_or_RGB col, const int rad = 1);
00126 
00127 //! Draw a rectangle of the given color and line width, with square corners
00128 template <class T_or_RGB>
00129 void drawRectSquareCorners(Image<T_or_RGB>& dst, const Rectangle &r,
00130                            const T_or_RGB color, const int linewidth);
00131 
00132 //! Draw a rectangle of color col and pixel radius rad, rotate by ori
00133 template <class T_or_RGB>
00134 void drawRectOR(Image<T_or_RGB>& dst,
00135                 const Rectangle& rect, const T_or_RGB col, const int rad = 1,
00136                 const float ori = 0.0F);
00137 
00138 //! Draw a rectangle of color col and pixel radius rad, no size assertions
00139 template <class T_or_RGB>
00140 void drawRectEZ(Image<T_or_RGB>& dst,
00141                 const Rectangle& rect, const T_or_RGB col, const int rad = 1);
00142 
00143 //! Draw a filled rectangle with the given fill value
00144 template <class T_or_RGB>
00145 void drawFilledRect(Image<T_or_RGB>& dst, const Rectangle& rect,
00146                     const T_or_RGB fillVal);
00147 
00148 //! Draw a cross of color col, half-size siz and pixel radius rad
00149 template <class T_or_RGB>
00150 void drawCross(Image<T_or_RGB>& dst,
00151                const Point2D<int>& p, const T_or_RGB col, const int siz = 3,
00152                const int rad = 1);
00153 
00154 //! Draw a cross of color col, half-size siz and pixel radius rad
00155 template <class T_or_RGB>
00156 void drawCrossOR(Image<T_or_RGB>& dst,
00157                const Point2D<int>& p, const T_or_RGB col, const int siz = 3,
00158                const int rad = 1, const float ori = 0.0F);
00159 
00160 //! Draw a square patch of color col and size siz
00161 template <class T_or_RGB>
00162 void drawPatch(Image<T_or_RGB>& dst,
00163                const Point2D<int>& p, const int siz, const T_or_RGB col);
00164 
00165 //! Draw a square patch of color col and size siz, with a black border
00166 template <class T_or_RGB>
00167 void drawPatchBB(Image<T_or_RGB>& dst,
00168                  const Point2D<int>& p, const int siz, const T_or_RGB col, const T_or_RGB bgcol = T_or_RGB());
00169 
00170 //! Draw a circle of color col and radius radius, with pixel radius rad
00171 template <class T_or_RGB>
00172 void drawCircle(Image<T_or_RGB>& dst,
00173                 const Point2D<int>& p, const int radius, const T_or_RGB col,
00174                 const int rad = 1);
00175 
00176 //! Draw an arrow from p1 to p2 with pixel radius rad
00177 template <class T_or_RGB>
00178 void drawArrow(Image<T_or_RGB>& dst,
00179                const Point2D<int>& p1, const Point2D<int>& p2, const T_or_RGB col,
00180                const int rad = 1);
00181 
00182 //! Draw a grid
00183 template <class T_or_RGB>
00184 void drawGrid(Image<T_or_RGB>& dst,
00185               const int spacingX, const int spacingY,
00186               const int thickX, const int thickY, const T_or_RGB col);
00187 
00188 //! Draw an nx * ny grid that exactly partitions the given image
00189 template <class T_or_RGB>
00190 void drawGrid(Image<T_or_RGB>& dst, const uint nx, const uint ny, 
00191               const int thick, const T_or_RGB col);
00192 
00193 //! Draw a 2D contour
00194 /*! Will draw a disk of color col and radius rad in dst at every point where src is on a contour. dst should be
00195     initialized ahd have same dims as src. Nothing is drawn for point off contours. */
00196 template <class T, class T_or_RGB>
00197 void drawContour2D(const Image<T>& src, Image<T_or_RGB>& dst, const T_or_RGB &col, const byte rad);
00198 
00199 enum TextAnchor
00200   {
00201     ANCHOR_TOP_LEFT,
00202     ANCHOR_TOP_RIGHT,
00203     ANCHOR_BOTTOM_LEFT,
00204     ANCHOR_BOTTOM_RIGHT
00205   };
00206 
00207 //! Write some text in normal font; only ASCII chars 32 .. 126 are supported
00208 /*! See Image/SimpleFont.H for font choices. */
00209 template <class T_or_RGB>
00210 void writeText(Image<T_or_RGB>& dst,
00211                const Point2D<int>& pt, const char* text,
00212                const T_or_RGB col = T_or_RGB(),
00213                const T_or_RGB bgcol = T_or_RGB(255),
00214                const SimpleFont& f = SimpleFont::FIXED(10),
00215                const bool transparent_bg = false,
00216                const TextAnchor anchor = ANCHOR_TOP_LEFT);
00217 
00218 /// Make an image containing one or more lines of text
00219 /** The function will choose a font width that fits the desired image
00220     size.
00221 
00222     @param w the desired width (in pixels) of the resulting image
00223     @param lines an array of strings to be written in the result, one
00224     line per string
00225     @param nlines the number of strings in the string array
00226     @param col the foreground color for the written text
00227     @param bg the background color for the written text
00228     @param max_chars_per_line if non-zero, then each line of text will
00229     be truncated at this many characters
00230     @param fontwidth the max font width unless it is zero, in which case
00231     it will be determined automatically to fit the text in the box.
00232  */
00233 template <class T_or_RGB>
00234 Image<T_or_RGB> makeMultilineTextBox(const int w,
00235                                      const std::string* lines,
00236                                      const size_t nlines,
00237                                      const T_or_RGB col,
00238                                      const T_or_RGB bg = T_or_RGB(),
00239                                      const size_t max_chars_per_line = 0,
00240                                      const int fontwidth = 0);
00241 
00242 //! draw a dot which is a point with 4 connected points
00243 /*! this is between the setVal method and drawCircle method for
00244   illustrating points
00245 */
00246 template <class T_or_RGB>
00247 void drawPoint(Image<T_or_RGB>& dst,
00248                int X,int Y, T_or_RGB pix);
00249 
00250 //! Draws a disk in image and check if it hits a target
00251 /*! @param mask input binary target mask to draw into
00252   @param center coordinates of disk center
00253   @param radius radisu of disk, in pixels
00254   @param value pixel value used to draw the disk
00255   @param targetval value with which the targets are represented
00256   @param floodval value to flood target with if target hit
00257   @return number of targets hit and flooded */
00258 template <class T>
00259 int drawDiskCheckTarget(Image<T>& dst,
00260                         Image<T>& mask, const Point2D<int>& center,
00261                         const int radius, const T value,
00262                         const T targetval, const T floodval);
00263 
00264 //! Warp image in 3D onto z-map
00265 /*! @param ima Input image
00266   @param zmap Height map of same size as ima
00267   @param pitch 3D pitch angle, in degrees
00268   @param yaw 3D yaw angle, in degrees
00269   @param dims The result will have these dimensions, unless the dimensions are
00270   empty (i.e. 0-by-0), in which case the result will be the best size computed
00271   from ima's size and the pitch and yaw angles.
00272 */
00273 template <class T>
00274 Image<PixRGB<T> > warp3D(const Image<PixRGB<T> >& ima,
00275                          const Image<float>& zmap,
00276                          const float pitch, const float yaw,
00277                          const float zMax, Dims& dims);
00278 
00279 //! Format a feature map for display
00280 /*! Take an Image<float> feature map as input and convert it to
00281   PixRGB<byte> by either multiplying the values by a factor or by
00282   normalizing them to 0 .. 255 (if factor is 0.0), and then using a
00283   given color map (which will also be displayed if showColorScale is
00284   true). Then rescale to the specified dims, using interpolation if
00285   desired. Then write a descriptor label in the top-left corner using
00286   a large font, and finally show the original range of values in the
00287   bottom-right corner uing a tiny font. */
00288 Image< PixRGB<byte> >
00289 formatMapForDisplay(const Image<float>& img, const float factor,
00290                     const Dims& newdims, const bool useInterp,
00291                     const ColorMap& cmap, const bool showColorScale,
00292                     const char *label);
00293 
00294 //! Generate a plot from a vector of points
00295 template <typename T, class U>
00296 Image< PixRGB<byte> > 
00297 linePlot(const U& points, 
00298          const int w, const int h, T minVal = T(), 
00299          T maxVal = T(), const char *title = "",
00300          const char *xLabel = "", const char *yLabel = "",
00301          const PixRGB<byte>& linecol=PixRGB<byte>(0,0,0),
00302          const PixRGB<byte>& bckcol=PixRGB<byte>(255,255,255));
00303 
00304 //! Draw a filled polygon with color col inside the polygon, no change outside
00305 template <class T_or_RGB>
00306 void drawFilledPolygon(Image<T_or_RGB>& img,
00307                        const std::vector<Point2D<int> >& polygon,
00308                        const T_or_RGB col);
00309 
00310 //! Simple struct to define a bargraph meter
00311 struct MeterInfo
00312 {
00313   std::string label;
00314   double val;
00315   double valmax;
00316   double thresh;
00317   PixRGB<byte> color;
00318 };
00319 
00320 //! Draw some bargraph meters
00321 Image<PixRGB<byte> > drawMeters(const MeterInfo* infos, const size_t ninfo,
00322                                 const size_t nx, const Dims& meterdims);
00323 
00324 
00325 // ######################################################################
00326 /* So things look consistent in everyone's emacs... */
00327 /* Local Variables: */
00328 /* indent-tabs-mode: nil */
00329 /* End: */
00330 
00331 
00332 #endif // !IMAGE_DRAWOPS_H_DEFINED

Generated on Sun Nov 22 13:42:25 2009 for iLab Neuromorphic Vision Toolkit by  doxygen 1.4.4