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

DebugWin.H

Go to the documentation of this file.
00001 /*!@file GUI/DebugWin.H A window class to show images  */
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: Lior Elazary <elazary@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/GUI/DebugWin.H $
00035 // $Id: DebugWin.H 11231 2009-05-27 20:24:37Z lior $
00036 //
00037 //
00038 
00039 #ifndef DEBUGWIN_H
00040 #define DEBUGWIN_H
00041 
00042 #include "GUI/XWinManaged.H"
00043 #include "Image/Point2D.H"
00044 #include "Image/Pixels.H"
00045 #include "Image/Transforms.H"
00046 #include "Image/ColorOps.H"
00047 #include "Image/ShapeOps.H"
00048 #include "Image/MathOps.H"
00049 #include "Image/DrawOps.H"
00050 #include "Image/CutPaste.H"
00051 #include "Envision/env_image.h"
00052 
00053 //debuging macros
00054 inline void SHOWIMG(Image<float> img, bool mag = false) {
00055   XWinManaged debug_xwin( img.getDims(), -1, -1, "DebugWin");
00056   Image<float> tmpImg = img;
00057   debug_xwin.drawImage(tmpImg);
00058   int key = -1;
00059   while(key != 24) //q to quite
00060   {
00061     key = debug_xwin.getLastKeyPress();
00062     Point2D<int>  p = debug_xwin.getLastMouseClick();
00063     if (p.isValid())
00064     {
00065       LINFO("Loc %ix%i pix value: %f", p.i, p.j, img.getVal(p));
00066 
00067       if (mag)
00068       {
00069         Dims dims(9,9);
00070         int tl_i = p.i - dims.w()/2;
00071         int tl_j = p.j - dims.h()/2;
00072 
00073         Image<float> c = crop(img, Point2D<int>(tl_i, tl_j), dims);
00074         SHOWIMG(rescaleNI(c, 256, 256));
00075       }
00076     }
00077 
00078     if (key == 58)  //m
00079     {
00080       Point2D<int> loc;
00081       float maxVal;
00082       findMax(img, loc, maxVal);
00083       LINFO("Max at %ix%i val=%f", loc.i, loc.j, maxVal);
00084       //img.setVal(loc, 0);
00085       drawDisk(img, loc, 6, 0.0F);
00086       drawCircle(tmpImg, loc, 6, maxVal);
00087       debug_xwin.drawImage(tmpImg);
00088     }
00089     usleep(10000);
00090   }
00091 }
00092 
00093 inline void SHOWIMG(Image<byte> img, bool mag = false) {
00094   XWinManaged debug_xwin( img.getDims(), -1, -1, "DebugWin");
00095   debug_xwin.drawImage(img);
00096   int key = -1;
00097   while(key != 24) //q to quite
00098   {
00099     key = debug_xwin.getLastKeyPress();
00100     Point2D<int>  p = debug_xwin.getLastMouseClick();
00101     if (p.isValid())
00102     {
00103       LINFO("Loc %ix%i pix value: %i", p.i, p.j, img.getVal(p));
00104 
00105       if (mag)
00106       {
00107         Dims dims(9,9);
00108         int tl_i = p.i - dims.w()/2;
00109         int tl_j = p.j - dims.h()/2;
00110 
00111         Image<float> c = crop(img, Point2D<int>(tl_i, tl_j), dims);
00112         SHOWIMG(rescaleNI(c, 256, 256));
00113       }
00114 
00115 
00116     }
00117     usleep(10000);
00118   }
00119 }
00120 
00121 inline void SHOWIMG(Image<PixRGB<byte> > img) {
00122 
00123   if (img.initialized())
00124   {
00125           XWinManaged debug_xwin( img.getDims(), -1, -1, "DebugWin");
00126           debug_xwin.drawImage(img);
00127           int key = -1;
00128           while(key != 24) //q to quit
00129           {
00130                   key = debug_xwin.getLastKeyPress();
00131                   Point2D<int>  p = debug_xwin.getLastMouseClick();
00132                   if (p.isValid())
00133                   {
00134                           PixRGB<byte> pix = img.getVal(p);
00135                           LINFO("Loc %ix%i pix value: (%i,%i,%i)", p.i, p.j, pix[0], pix[1], pix[2]);
00136                   }
00137                   usleep(10000);
00138           }
00139   }
00140 }
00141 
00142 inline void ENV_SHOWIMG(struct env_image *img, int w=-1, int h=-1) {
00143 
00144   if (w == -1 || h == -1)
00145   {
00146     w = img->dims.w;
00147     h = img->dims.h;
00148   }
00149 
00150 
00151   XWinManaged debug_xwin(Dims(w,h), -1, -1, "DebugWin");
00152 
00153   Image<float> outImg(img->dims.w, img->dims.h, NO_INIT);
00154   const intg32* const src = img->pixels;
00155   const env_size_t sz = env_img_size(img);
00156   float* outImgPtr = outImg.getArrayPtr();
00157 
00158   for (env_size_t i = 0; i < sz; ++i)
00159    outImgPtr[i] = (float) src[i];
00160 
00161   outImg = rescale(outImg, w, h);
00162 
00163   debug_xwin.drawImage(outImg);
00164   int key = -1;
00165   while(key != 24) //q to quite
00166   {
00167     key = debug_xwin.getLastKeyPress();
00168     Point2D<int>  p = debug_xwin.getLastMouseClick();
00169     if (p.isValid())
00170     {
00171       LINFO("Loc %ix%i pix value: %f", p.i, p.j, outImg.getVal(p));
00172     }
00173     usleep(10000);
00174   }
00175 }
00176 
00177 
00178 
00179 
00180 #endif

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