00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CImageFloat_H 00029 #define CImageFloat_H 00030 00031 #include <mrpt/utils/utils_defs.h> 00032 #include <mrpt/utils/CSerializable.h> 00033 #include <mrpt/utils/CCanvas.h> 00034 #include <mrpt/math/CMatrixTemplateNumeric.h> 00035 00036 namespace mrpt 00037 { 00038 namespace utils 00039 { 00040 00041 // This must be added to any CSerializable derived class: 00042 DEFINE_SERIALIZABLE_PRE( CImageFloat ) 00043 00044 /** In this class a grayscale image can be stored with float-type pixels. 00045 * I/O is supported as conversion to a byte-type pixels "CImage", and as binary dump using the 00046 * CSerializable interface(<< and >> operators), just as most objects in the MRPT library. This format 00047 * is not compatible with any standarized image format. <br> 00048 * Additional notes: <br> 00049 * - Only the top-left coordinates origin format is supported. 00050 * - The format of the pixels is valid float values in the range [0,1] 00051 * - When assigning a CImage to a CImageFloat, the pixels are automatically converted from the range (0,255) --> (0,1) 00052 * - There is a "=" operator for converting between the classes "CImage" and "CImageFloat". 00053 * 00054 * 00055 * \sa CImage, CSerializable 00056 */ 00057 class MRPTDLLIMPEXP CImageFloat : public mrpt::utils::CSerializable, public CCanvas 00058 { 00059 friend class CImage; 00060 00061 DEFINE_SERIALIZABLE( CImageFloat ) 00062 00063 protected: 00064 /** Data members 00065 */ 00066 float *m_img; 00067 00068 /** The image size: 00069 */ 00070 size_t m_width,m_height; 00071 00072 public: 00073 /** Changes the value of the pixel (x,y). 00074 * Pixel coordinates starts at the left-top corner of the image, and start in (0,0). 00075 * The meaning of the parameter "color" depends on the implementation: it will usually 00076 * be a 24bit RGB value (0x00RRGGBB), but it can also be just a 8bit gray level. 00077 * This method must support (x,y) values OUT of the actual image size without neither 00078 * raising exceptions, nor leading to memory access errors. 00079 */ 00080 void setPixel(int x, int y, size_t color); 00081 00082 /** Resize the buffer "img" to accomodate a new image size. 00083 */ 00084 void resize( 00085 size_t width, 00086 size_t height); 00087 00088 /** Resize the buffer "img" to accomodate a new image size. 00089 * Initialize all images pixels to zero. 00090 * by AJOGD @ JAN-2007 00091 */ 00092 void setSize( 00093 size_t width, 00094 size_t height); 00095 00096 /** Default constructor: 00097 */ 00098 CImageFloat( size_t width = 1, 00099 size_t height = 1 ); 00100 00101 /** Copy constructor: 00102 */ 00103 CImageFloat( const CImageFloat &o ); 00104 00105 /** Copy constructor from a matrix with values in the range [0,1]: 00106 */ 00107 explicit CImageFloat( const math::CMatrixFloat &o ); 00108 00109 /** Copy constructor from a matrix with values in the range [0,1]: 00110 */ 00111 explicit CImageFloat( const math::CMatrixDouble &o ); 00112 00113 /** Copy constructor from a CImage. 00114 */ 00115 explicit CImageFloat( const CImage &o ); 00116 00117 /** Copy operator 00118 */ 00119 void operator = (const CImageFloat& o); 00120 00121 /** Copy operator 00122 */ 00123 void operator = (const CImage& o); 00124 00125 /** Copy operator from a float matrix. */ 00126 void operator = (const math::CMatrixFloat& o); 00127 00128 /** Copy operator from a double matrix. */ 00129 void operator = (const math::CMatrixDouble& o); 00130 00131 /** Destructor: 00132 */ 00133 virtual ~CImageFloat( ); 00134 00135 /** Returns the width of the image in pixels 00136 */ 00137 size_t getWidth() const; 00138 00139 /** Returns the height of the image in pixels 00140 */ 00141 size_t getHeight() const; 00142 00143 /** Returns a matrix CMatrix representation of the image. 00144 * The output matrix will contain at its (r,c) element the 00145 * pixel at the r'th row (y coordinate), and c'th column (x coordinate) 00146 */ 00147 void getAsMatrix( math::CMatrixFloat &outMatrix ) const; 00148 00149 /** Loads the image from a gray-scale image file. 00150 * See CImage::loadFromFile for supported formats 00151 * \return False on any error 00152 */ 00153 bool loadFromFile( const std::string& fileName ); 00154 00155 /** Save the image to a file in a format given by the file extension. 00156 * If "verticalFlip" is true, the image is inverted vertically 00157 * See CImage::saveToFile for supported formats 00158 * \return False on any error 00159 */ 00160 bool saveToFile(const std::string &fileName, bool verticalFlip = false) const; 00161 00162 /** Save to a text file, loadable from matlab 00163 */ 00164 void saveToTextFile(const std::string &fileName) const; 00165 00166 /** Adjusts the range of the values in the image, such as the minimum and maximum values are the given ones. 00167 */ 00168 void adjustImageRange(float min=0.0f, float max=1.0f); 00169 00170 /** Returns a pointer to a given pixel. 00171 * The coordinate origin is pixel(0,0)=top-left corner of the image. 00172 * \exception std::exception On pixel coordinates out of bounds 00173 */ 00174 float* operator()(size_t col, size_t row) const; 00175 00176 /** Point-wise product of CImageFloat images 00177 * by FAMD, JAN-2007 00178 */ 00179 CImageFloat operator*( const CImageFloat &im2 ); 00180 /** Point-wise addition of CImageFloat images 00181 * by FAMD, JAN-2007 00182 */ 00183 CImageFloat operator+( const CImageFloat &im2 ); 00184 /** Point-wise substraction of CImageFloat images 00185 * by FAMD, JAN-2007 00186 */ 00187 CImageFloat operator-( const CImageFloat &im2 ); 00188 /** Point-wise scalar power of CImageFloat images 00189 * by FAMD, JAN-2007 00190 */ 00191 CImageFloat operator^( int exp ); 00192 00193 /** Substitutes this image with a new one scaled down to half its original size. 00194 */ 00195 void scaleHalf(); 00196 00197 00198 }; // End of class 00199 00200 typedef CImageFloat CMRPTImageFloat; //!< Deprecated name. 00201 00202 00203 } // end of namespace utils 00204 } // end of namespace mrpt 00205 00206 #endif
Page generated by Doxygen 1.5.7.1 for MRPT 0.7.1 SVN: at Mon Aug 17 22:58:25 EDT 2009 |