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 13898 2010-09-09 01:19:08Z 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 "Raster/Raster.H" 00051 #include "Image/CutPaste.H" 00052 #include "Envision/env_image.h" 00053 00054 //debuging macros 00055 inline void SHOWIMG(Image<float> img, bool mag = false) { 00056 XWinManaged debug_xwin( img.getDims(), -1, -1, "DebugWin"); 00057 Image<float> tmpImg = img; 00058 debug_xwin.drawImage(tmpImg); 00059 int key = -1; 00060 while(key != 24) //q to quite 00061 { 00062 key = debug_xwin.getLastKeyPress(); 00063 Point2D<int> p = debug_xwin.getLastMouseClick(); 00064 if (p.isValid()) 00065 { 00066 LINFO("Loc %ix%i pix value: %f", p.i, p.j, img.getVal(p)); 00067 00068 if (mag) 00069 { 00070 Dims dims(9,9); 00071 int tl_i = p.i - dims.w()/2; 00072 int tl_j = p.j - dims.h()/2; 00073 00074 Image<float> c = crop(img, Point2D<int>(tl_i, tl_j), dims); 00075 SHOWIMG(rescaleNI(c, 256, 256)); 00076 } 00077 } 00078 00079 if (key == 58) //m 00080 { 00081 Point2D<int> loc; 00082 float maxVal; 00083 findMax(img, loc, maxVal); 00084 LINFO("Max at %ix%i val=%f", loc.i, loc.j, maxVal); 00085 //img.setVal(loc, 0); 00086 drawDisk(img, loc, 6, 0.0F); 00087 drawCircle(tmpImg, loc, 6, maxVal); 00088 debug_xwin.drawImage(tmpImg); 00089 } 00090 usleep(10000); 00091 } 00092 } 00093 00094 inline void SHOWIMG(Image<byte> img, bool mag = false) { 00095 XWinManaged debug_xwin( img.getDims(), -1, -1, "DebugWin"); 00096 debug_xwin.drawImage(img); 00097 int key = -1; 00098 while(key != 24) //q to quite 00099 { 00100 key = debug_xwin.getLastKeyPress(); 00101 Point2D<int> p = debug_xwin.getLastMouseClick(); 00102 if (p.isValid()) 00103 { 00104 LINFO("Loc %ix%i pix value: %i", p.i, p.j, img.getVal(p)); 00105 00106 if (mag) 00107 { 00108 Dims dims(9,9); 00109 int tl_i = p.i - dims.w()/2; 00110 int tl_j = p.j - dims.h()/2; 00111 00112 Image<float> c = crop(img, Point2D<int>(tl_i, tl_j), dims); 00113 SHOWIMG(rescaleNI(c, 256, 256)); 00114 } 00115 00116 00117 } 00118 usleep(10000); 00119 } 00120 } 00121 00122 inline void SHOWIMG(Image<PixRGB<byte> > img) { 00123 00124 if (img.initialized()) 00125 { 00126 XWinManaged debug_xwin( img.getDims(), -1, -1, "DebugWin"); 00127 debug_xwin.drawImage(img); 00128 int key = -1; 00129 while(key != 24) //q to quit 00130 { 00131 key = debug_xwin.getLastKeyPress(); 00132 Point2D<int> p = debug_xwin.getLastMouseClick(); 00133 if (p.isValid()) 00134 { 00135 PixRGB<byte> pix = img.getVal(p); 00136 LINFO("Loc %ix%i pix value: (%i,%i,%i)", p.i, p.j, pix[0], pix[1], pix[2]); 00137 } 00138 if (key == 25) //write image 00139 Raster::WriteRGB(img, "DebugWin.ppm"); 00140 usleep(10000); 00141 } 00142 } 00143 } 00144 00145 inline void ENV_SHOWIMG(struct env_image *img, int w=-1, int h=-1) { 00146 00147 if (w == -1 || h == -1) 00148 { 00149 w = img->dims.w; 00150 h = img->dims.h; 00151 } 00152 00153 00154 XWinManaged debug_xwin(Dims(w,h), -1, -1, "DebugWin"); 00155 00156 Image<float> outImg(img->dims.w, img->dims.h, NO_INIT); 00157 const intg32* const src = img->pixels; 00158 const env_size_t sz = env_img_size(img); 00159 float* outImgPtr = outImg.getArrayPtr(); 00160 00161 for (env_size_t i = 0; i < sz; ++i) 00162 outImgPtr[i] = (float) src[i]; 00163 00164 outImg = rescale(outImg, w, h); 00165 00166 debug_xwin.drawImage(outImg); 00167 int key = -1; 00168 while(key != 24) //q to quite 00169 { 00170 key = debug_xwin.getLastKeyPress(); 00171 Point2D<int> p = debug_xwin.getLastMouseClick(); 00172 if (p.isValid()) 00173 { 00174 LINFO("Loc %ix%i pix value: %f", p.i, p.j, outImg.getVal(p)); 00175 } 00176 usleep(10000); 00177 } 00178 } 00179 00180 00181 00182 00183 #endif