00001 /*!@file Raster/Raster.H Writes a raster image to disk / reads it / displays it */ 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: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Raster/Raster.H $ 00035 // $Id: Raster.H 10547 2008-12-18 21:37:57Z dparks $ 00036 // 00037 00038 #ifndef RASTER_H_DEFINED 00039 #define RASTER_H_DEFINED 00040 00041 #include "Image/ArrayData.H" 00042 #include "Image/Normalize.H" // for float normalization flags 00043 #include "Raster/RasterFileFormat.H" 00044 #include "Util/Types.H" 00045 #include "Util/sformat.H" 00046 00047 #include <string> 00048 00049 class GenericFrame; 00050 class GenericFrameSpec; 00051 class VideoFrame; 00052 template <class T> class Image; 00053 template <class T> class PixRGB; 00054 00055 // ###################################################################### 00056 //! For reading, writing and displaying images. 00057 /*! Raster works with PGM files (for grayscale images) and PPM files 00058 (for RGB images). Selection between PGM and PPM given the 00059 RASFMT_PNM RasterFileFormat is automatic based on whether the 00060 image is greyscale or color. In addition, it offers PNG read 00061 capability (grayscale, RGB, or color-palette, at any bit-depth), 00062 and write capability (8-bit grayscale and RGB). Similarly, it 00063 offers write capability for RASFMT_RAW_IMAGE data (straight pixel 00064 data with no header information), but no such read 00065 capability. Both the raw and ASCII variants of PGM/PPM files are 00066 supported. Display of images uses the program "xv" to output 00067 images to the screen. The filename argument is passed to the 00068 various methods of this class in the same way as in printf(). */ 00069 namespace Raster 00070 { 00071 // ###################################################################### 00072 // Read/Write in various formats, for byte-based images: 00073 00074 //! Return true if file exists on disk 00075 /*! If ftype is RASFMT_AUTO, then the raster file type is inferred 00076 from the filename. 00077 */ 00078 bool fileExists(std::string fname, 00079 const RasterFileFormat ftype = RASFMT_AUTO, 00080 const bool chkFormat = false); 00081 00082 //! Get image comments without fully reading the image (PPM only) 00083 /*! If ftype is RASFMT_AUTO, then the raster file type is inferred 00084 from the filename. 00085 */ 00086 std::string getImageComments(std::string fname, 00087 const RasterFileFormat ftype = RASFMT_AUTO); 00088 00089 //! Get image dimensions without fully reading the image 00090 /*! If ftype is RASFMT_AUTO, then the raster file type is inferred 00091 from the filename. 00092 */ 00093 Dims getImageDims(std::string fname, 00094 const RasterFileFormat ftype = RASFMT_AUTO); 00095 00096 //! Get image specifications without fully reading the image 00097 /*! If ftype is RASFMT_AUTO, then the raster file type is inferred 00098 from the filename. 00099 */ 00100 GenericFrameSpec getFrameSpec(std::string fname, 00101 const RasterFileFormat ftype = RASFMT_AUTO); 00102 00103 //! Read a GenericFrame from a raster file. 00104 /*! This can subsequently be converted to rgb, grayscale, 00105 floating-point, or video-yuv. 00106 00107 If ftype is RASFMT_AUTO, then the raster file type is inferred 00108 from the filename. 00109 */ 00110 GenericFrame ReadFrame(std::string fname, 00111 RasterFileFormat ftype = RASFMT_AUTO); 00112 00113 //! Read an RGB byte image from a raster file 00114 /*! Just calls ReadFrame() internally. 00115 00116 If ftype is RASFMT_AUTO, then the raster file type is inferred 00117 from the filename. 00118 */ 00119 Image<PixRGB<byte> > ReadRGB(std::string fname, 00120 RasterFileFormat ftype = RASFMT_AUTO); 00121 00122 //! Read a greyscale byte image from a greyscale raster file 00123 /*! Just calls ReadFrame() internally. 00124 00125 If ftype is RASFMT_AUTO, then the raster file type is inferred 00126 from the filename. 00127 */ 00128 Image<byte> ReadGray(std::string fname, 00129 RasterFileFormat ftype = RASFMT_AUTO); 00130 00131 //! Read a greyscale byte image, converting to NTSC coordinates if necessary 00132 /*! Just calls ReadFrame() internally. 00133 00134 If ftype is RASFMT_AUTO, then the raster file type is inferred 00135 from the filename. 00136 */ 00137 Image<byte> ReadGrayNTSC(std::string fname, 00138 const RasterFileFormat ftype = RASFMT_AUTO); 00139 00140 //! Read a greyscale float image from a greyscale raster file 00141 /*! Just calls ReadFrame() internally. 00142 00143 If ftype is RASFMT_AUTO, then the raster file type is inferred 00144 from the filename. 00145 */ 00146 Image<float> ReadFloat(std::string fname, 00147 RasterFileFormat ftype = RASFMT_AUTO); 00148 00149 //! Read a VideoFrame from a raster file 00150 /*! Just calls ReadFrame() internally. 00151 00152 If ftype is RASFMT_AUTO, then the raster file type is inferred 00153 from the filename. 00154 */ 00155 VideoFrame ReadVideo(std::string fname, 00156 RasterFileFormat ftype = RASFMT_AUTO); 00157 00158 //! Write a GenericFrame to a raster file 00159 /*! The GenericFrame could be constructed from rgb, grayscale, 00160 floating-point, or video-yuv. 00161 00162 Returns the full name of the image file that was actually 00163 written; this may differ slightly from fname if a filename 00164 extension was added to match ftype. 00165 00166 If ftype is RASFMT_AUTO, then the raster file type is inferred 00167 from the filename. 00168 */ 00169 std::string WriteFrame(const GenericFrame& image, 00170 std::string fname, 00171 RasterFileFormat ftype = RASFMT_AUTO); 00172 00173 //! Write an RGB byte image to a raster file 00174 /*! Just calls WriteFrame() internally. 00175 00176 Returns the full name of the image file that was actually 00177 written; this may differ slightly from fname if a filename 00178 extension was added to match ftype. 00179 00180 If ftype is RASFMT_AUTO, then the raster file type is inferred 00181 from the filename. 00182 */ 00183 std::string WriteRGB(const Image< PixRGB<byte> >& image, 00184 std::string fname, 00185 const RasterFileFormat ftype = RASFMT_AUTO); 00186 00187 //! Write a grayscale byte image to a raster file 00188 /*! Just calls WriteFrame() internally. 00189 00190 Returns the full name of the image file that was actually 00191 written; this may differ slightly from fname if a filename 00192 extension was added to match ftype. 00193 00194 If ftype is RASFMT_AUTO, then the raster file type is inferred 00195 from the filename. 00196 */ 00197 std::string WriteGray(const Image<byte>& image, 00198 std::string fname, 00199 const RasterFileFormat ftype = RASFMT_AUTO); 00200 00201 //! Write a float image to a raster file 00202 /*! Just calls WriteFrame() internally. 00203 00204 Returns the full name of the image file that was actually 00205 written; this may differ slightly from fname if a filename 00206 extension was added to match ftype. 00207 00208 If ftype is RASFMT_AUTO, then the raster file type is inferred 00209 from the filename. 00210 */ 00211 std::string WriteFloat(const Image<float>& image, 00212 const int flags, std::string fname, 00213 const RasterFileFormat ftype = RASFMT_AUTO); 00214 00215 //! Turn off the use of xv 00216 /*! Turn off xv, so that calls to Display() do nothing, and calls to 00217 Visu() just save the image to disk without displaying it onscreen. */ 00218 void NoXV(); 00219 00220 //! calls xv to display an image that is on disk 00221 void Display(const char* file); 00222 00223 //! wait for the [return] key 00224 void waitForKey(); 00225 00226 // save image and display it: 00227 00228 //! Save image of type Image< PixRGB<byte> > to disk then display it using xv 00229 /*! If ftype is RASFMT_AUTO, then the raster file type is inferred 00230 from the filename. 00231 */ 00232 void VisuRGB(const Image< PixRGB<byte> >& image, 00233 std::string fname, 00234 const RasterFileFormat ftype = RASFMT_AUTO); 00235 00236 //! Save image of type Image<byte> to disk then display it using xv 00237 /*! If ftype is RASFMT_AUTO, then the raster file type is inferred 00238 from the filename. 00239 */ 00240 void VisuGray(const Image<byte>& image, 00241 std::string fname, 00242 const RasterFileFormat ftype = RASFMT_AUTO); 00243 00244 //! Save image of type Image<float> to disk then display it using xv 00245 /*! If ftype is RASFMT_AUTO, then the raster file type is inferred 00246 from the filename. 00247 */ 00248 void VisuFloat(const Image<float>& image, 00249 const int flags, 00250 std::string fname, 00251 const RasterFileFormat ftype = RASFMT_AUTO); 00252 }; 00253 00254 /* So things look consistent in everyone's emacs... */ 00255 /* Local Variables: */ 00256 /* indent-tabs-mode: nil */ 00257 /* End: */ 00258 00259 #endif