00001 /*!@file TIGS/TigsInputFrame.H Class that lets us do lazy computation of luminance/rg/by from an input frame */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 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; 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 at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/TIGS/TigsInputFrame.H $ 00035 // $Id: TigsInputFrame.H 9412 2008-03-10 23:10:15Z farhan $ 00036 // 00037 00038 #ifndef TIGS_TIGSINPUTFRAME_H_DEFINED 00039 #define TIGS_TIGSINPUTFRAME_H_DEFINED 00040 00041 #include "Image/Hash.H" 00042 #include "Image/Image.H" 00043 #include "Image/Pixels.H" 00044 #include "Util/SimTime.H" 00045 #include "Util/log.H" 00046 #include "rutz/shared_ptr.h" 00047 00048 /// Class that lets us do lazy computation of luminance/rg/by from an input frame 00049 class TigsInputFrame 00050 { 00051 public: 00052 TigsInputFrame(const Image<PixRGB<byte> >& in, const SimTime& t) 00053 : 00054 itsGhost(false), 00055 itsTime(t), itsHashInited(false), 00056 itsOrigbounds(in.getBounds()), 00057 itsOrigframe(in) 00058 { 00059 // obviously hackish -- but for now there are various places in 00060 // this file where we make the implicit assumption of 640x480 00061 // input, so let's just verify it at the get-go here: 00062 ASSERT(in.getDims() == Dims(640,480)); 00063 } 00064 00065 TigsInputFrame(const SimTime& t, const Dims& dims, 00066 const Digest<16>& hash) 00067 : 00068 itsGhost(true), 00069 itsTime(t), itsHashInited(true), itsHash(hash), 00070 itsOrigbounds(Rectangle(Point2D<int>(0,0), dims)) 00071 { 00072 ASSERT(dims == Dims(640,480)); 00073 } 00074 00075 static rutz::shared_ptr<TigsInputFrame> 00076 fromGhostString(const std::string& s); 00077 00078 std::string toGhostString() const; 00079 00080 bool isGhost() const { return itsGhost; } 00081 00082 SimTime t() const 00083 { return itsTime; } 00084 00085 Digest<16> getHash() const 00086 { 00087 if (!itsHashInited) 00088 { 00089 if (itsGhost) 00090 LFATAL("ghost frames must have a precomputed hash"); 00091 00092 // let's hash the simtime into the digest as well: 00093 const int msec = int(itsTime.msecs()); 00094 00095 itsHash = md5rgb(&itsOrigframe, &msec, sizeof(msec)); 00096 itsHashInited = true; 00097 } 00098 00099 return itsHash; 00100 } 00101 00102 const Rectangle& origbounds() const 00103 { return itsOrigbounds; } 00104 00105 const Image<PixRGB<byte> >& origframe() const 00106 { 00107 if (itsGhost) 00108 LFATAL("origframe() not allowed for ghost frames"); 00109 00110 return itsOrigframe; 00111 } 00112 00113 const Image<PixRGB<byte> >& rgb() const 00114 { 00115 if (itsGhost) 00116 LFATAL("rgb() not allowed for ghost frames"); 00117 00118 initialize(); 00119 return itsRGB; 00120 } 00121 00122 const Image<float>& lum() const 00123 { 00124 if (itsGhost) 00125 LFATAL("lum() not allowed for ghost frames"); 00126 00127 initialize(); 00128 return itsLum; 00129 } 00130 00131 const Image<float>& rg() const 00132 { 00133 if (itsGhost) 00134 LFATAL("rg() not allowed for ghost frames"); 00135 00136 initialize(); 00137 return itsRG; 00138 } 00139 00140 const Image<float>& by() const 00141 { 00142 if (itsGhost) 00143 LFATAL("by() not allowed for ghost frames"); 00144 00145 initialize(); 00146 return itsBY; 00147 } 00148 00149 private: 00150 void initialize() const; 00151 00152 bool itsGhost; 00153 00154 SimTime itsTime; 00155 00156 mutable bool itsHashInited; 00157 mutable Digest<16> itsHash; 00158 00159 Rectangle itsOrigbounds; 00160 00161 Image<PixRGB<byte> > itsOrigframe; 00162 mutable Image<PixRGB<byte> > itsRGB; 00163 mutable Image<float> itsLum; 00164 mutable Image<float> itsRG; 00165 mutable Image<float> itsBY; 00166 }; 00167 00168 // ###################################################################### 00169 /* So things look consistent in everyone's emacs... */ 00170 /* Local Variables: */ 00171 /* mode: c++ */ 00172 /* indent-tabs-mode: nil */ 00173 /* End: */ 00174 00175 #endif // TIGS_TIGSINPUTFRAME_H_DEFINED