last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998-2004 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 00042 /** 00043 * \file cvrImage.h 00044 * Contains the color image data structure of the CVR-Lib , which is 00045 * a matrix of cvr::rgbaPixel 00046 * \author Pablo Alvarado 00047 * \date 09.04.1999 00048 * 00049 * $Id: cvrImage.h,v 1.10 2007/10/19 03:55:06 alvarado Exp $ 00050 */ 00051 00052 #ifndef _CVR_IMAGE_H_ 00053 #define _CVR_IMAGE_H_ 00054 00055 #include "cvrMatrix.h" 00056 #include "cvrRGBAPixel.h" 00057 00058 namespace cvr { 00059 class channel8; 00060 class channel; 00061 class channel32; 00062 00063 /** 00064 * The one and only RGBA-image format. 00065 * 00066 * This class is an specialization of a matrix of cvr::rgbaPixel. 00067 * 00068 * The concept for color images and gray valued images in the CVR-Lib is 00069 * simple: they are specializations of the class cvr::matrix. 00070 * 00071 * Several aspects must however be clarified. The rows of the matrix will 00072 * represent horizontal lines in the image, and the columns vertical ones. 00073 * The row with index zero will be the row at the top of the image. The 00074 * column with row zero is the one at the left of the image. This means 00075 * that the used coordinate system for the position of a pixel is 00076 * "left-handed": the origin is situated at the top-left corner of the 00077 * image, the x-coordinate gives the position in the horizontal axis and 00078 * the y-coordinate the position in the vertical axis. In other words, 00079 * the y coordinate give the row and x the column of the matrix. 00080 * This fact is important to remember when accessing the image elements: 00081 * 00082 * \code 00083 * image img; // our image 00084 * if (img.at(y,x) == img[y][x] == img.at(point(x,y))) { 00085 * cout << "This is always true!"; 00086 * } else { 00087 * cout << "ERROR: it's imposible to get here"; 00088 * exit 1; 00089 * } 00090 * \endcode 00091 * 00092 * The gray valued channels cvr::channel and cvr::channel8 differ on 00093 * the type and valid value ranges of their elements. The former 00094 * accepts floating point values, with a default value range from 00095 * 0.0 to 1.0. Many algorithms produce other values with specific 00096 * meanings like angles or gradients, but using the default range you can 00097 * assume 0.0 as a representation for black and 1.0 for white. 00098 * 00099 * The cvr::channel8 is a much smaller representation but allows 00100 * only integer values between 0 and 255, fact that can be advantageous 00101 * in many algorithms. Here 0 usually means black and 255 white. 00102 * 00103 * The cvr::image as cvr::matrix<cvr::rgbaPixel> allows the representation of 00104 * true-color images, i.e. images with pixels that can be chosen from a 00105 * palette of more than 16 million colors. 00106 * 00107 * @see cvr::matrix for a reference to all inherited methods. 00108 * 00109 * @ingroup gAggregate 00110 * @ingroup gColor 00111 * @ingroup gImageProcessing 00112 */ 00113 class image : public matrix<rgbaPixel> { 00114 public: 00115 /** 00116 * Default constructor creates an empty image 00117 */ 00118 image(); 00119 00120 /** 00121 * Create a connected \c rows x \c cols image but leave all 00122 * elements uninitialized 00123 * 00124 * @param rows number of rows of the image 00125 * @param cols number of columns of the image 00126 */ 00127 image(const int rows,const int cols); 00128 00129 /** 00130 * Create a connected \c size.y x \c size.x image but leave all 00131 * elements uninitialized. 00132 * 00133 * @param size cvr::point with the size of the image 00134 * (size.x is the number of columns and 00135 * size.y the number of rows) 00136 */ 00137 image(const ipoint& size); 00138 00139 /** 00140 * Create a connected \c rows x \c cols image and initializes all 00141 * elements with \a iniValue 00142 * 00143 * @param rows number of rows of the image 00144 * @param cols number of columns of the image 00145 * @param iniValue all elements will be initialized with this value 00146 */ 00147 image(const int rows,const int cols, 00148 const rgbaPixel& iniValue); 00149 00150 /** 00151 * Creates a connected \c size.y x \c size.x image and initializes 00152 * all elements with \a iniValue 00153 * @param size cvr::point with the size of the image 00154 * (size.x is the number of columns and 00155 * size.y the number of rows) 00156 * @param iniValue all elements will be initialized with this value 00157 */ 00158 image(const ipoint& size,const rgbaPixel& iniValue); 00159 00160 /** 00161 * Creates a connected \c rows x \c cols image and initializes all 00162 * elements with the data pointed by \a data. The first 00163 * \a cols-elements of the data will be copied on the first row, 00164 * the next ones on the second row and so on. 00165 * 00166 * @param rows number of rows of the image 00167 * @param cols number of columns of the image 00168 * @param data pointer to the memory block with the data to be initialized 00169 * with. 00170 */ 00171 image(const int rows,const int cols,const rgbaPixel data[]); 00172 00173 /** 00174 * Copy constructor. 00175 * 00176 * @param other the image to be copied. 00177 */ 00178 image(const image& other); 00179 00180 /** 00181 * Copy constructor. 00182 * 00183 * Create a subimage of the other image 00184 * 00185 * @param other the image to be copied. 00186 * @param from initial coordinates of the window. 00187 * @param to final coordinates of the window. 00188 */ 00189 image(const image& other, 00190 const ipoint& from, 00191 const ipoint& to); 00192 00193 /** 00194 * Copy constructor. 00195 * 00196 * Create this image as a connected copy of another image 00197 * for this const version, the data will be always copied! 00198 * It is also possible to create a copy of a subimage of another image. 00199 * 00200 * @param other the image to be copied. 00201 * @param fromRow initial row of the other image to be copied 00202 * @param toRow last row to be copied of the other image 00203 * @param fromCol initial column of the other image to be copied 00204 * @param toCol last column to be copied of the other image 00205 * 00206 * Example: 00207 * \code 00208 * cvr::image m(4,6,0); // image with 24 elements 00209 * // ... 00210 * // initialize image with: 00211 * // 0 1 2 3 4 5 00212 * // 2 1 5 4 0 3 00213 * // 1 2 1 2 3 2 00214 * // 3 3 2 1 2 3 00215 * 00216 * cvr::image sm(m,1,3,0,2) // this line will lead to the 00217 * // following contents for sm: 00218 * // 1 2 3 00219 * // 1 5 4 00220 * // 2 1 2 00221 * \endcode 00222 * 00223 */ 00224 image(const image& other, 00225 const int fromRow, 00226 const int fromCol=0, 00227 const int toRow=MaxIndex, 00228 const int toCol=MaxIndex); 00229 00230 /** 00231 * Returns the name of this type. 00232 */ 00233 virtual const std::string& name() const; 00234 00235 /** 00236 * Create a clone of this image 00237 * @return a pointer to a copy of this image 00238 */ 00239 virtual image* clone() const; 00240 00241 /** 00242 * Create a new empty image 00243 * @return a pointer to the new image 00244 */ 00245 virtual image* newInstance() const; 00246 00247 /** 00248 * Cast from the \a other matrix<ubyte>, interpreted as a channel8. 00249 * 00250 * For the transformation it assumes the channel8 as a gray valued 00251 * channel where 0 means black and 255 means white. 00252 * 00253 * @param other the channel8 to be cast 00254 * @return a reference to this image 00255 * 00256 * Example: 00257 * \code 00258 * cvr::channel8 matA(10,10,255); // a channel8 00259 * cvr::image matB; // an image 00260 * 00261 * matB.castFrom(matA); // this will copy matA in matB!! 00262 * // and all elements will have 00263 * // rgbaPixel(255,255,255) 00264 * \endcode 00265 */ 00266 image& castFrom(const matrix<ubyte>& other); 00267 00268 /** 00269 * Cast from the \a other fmatrix, intepreted as a single precision 00270 * floating point channel. 00271 * 00272 * For the transformation it assumes the channel as a gray valued 00273 * channel where 0 means black and 1.0f means white. All other 00274 * values will be clipped (less than zero to zero and more than 1.0 to 1.0) 00275 * 00276 * @param other the channel8 to be cast 00277 * @param minToBlack if minToBlack is true, a linear gray-valued 00278 * tranformation will be applied, which maps the minimal value in 00279 * the channel to (0,0,0). If false, the value zero will be mapped 00280 * to zero. 00281 * @param maxToWhite if maxToWhite is true, a linear gray-valued 00282 * transformation will be applied, which maps the maximal value in 00283 * the channel to (255,255,255). If false, the value 1.0f will be 00284 * mapped to 255. 00285 * @return a reference to this image 00286 * Example: 00287 * \code 00288 * cvr::channel matA(10,10,1.0f); // a channel 00289 * cvr::image matB; // an image 00290 * 00291 * matB.castFrom(matA); // this will copy matA in matB!! 00292 * // and all elements will have 00293 * // rgbaPixel(255,255,255) 00294 * \endcode 00295 */ 00296 image& castFrom(const fmatrix& other, 00297 const bool minToBlack = false, 00298 const bool maxToWhite = false); 00299 00300 /** 00301 * Cast from the \a other channel32. 00302 * For the transformation it assumes the channel as a gray valued 00303 * channel where 0 means black and 1.0f means white. All other 00304 * values will be clipped (less than zero to zero and more than 1.0 to 1.0) 00305 * 00306 * @param other the channel32 to be cast 00307 * @param minToBlack if minToBlack is true, a linear gray-valued 00308 * tranformation will be applied, which maps the minimal value in 00309 * the channel to (0,0,0). If false, the value zero will be mapped 00310 * to zero. 00311 * @param maxToWhite if maxToWhite is true, a linear gray-valued 00312 * transformation will be applied, which maps the maximal value in 00313 * the channel to (255,255,255). If false, the value 1.0f will be 00314 * mapped to 255. 00315 * @return a reference to this image 00316 * Example: 00317 * \code 00318 * cvr::channel matA(10,10,1.0f); // a channel 00319 * cvr::image matB; // an image 00320 * 00321 * matB.castFrom(matA); // this will copy matA in matB!! 00322 * // and all elements will have 00323 * // rgbaPixel(255,255,255) 00324 * \endcode 00325 */ 00326 image& castFrom(const matrix<int32>& other, 00327 const bool minToBlack = false, 00328 const bool maxToWhite = false); 00329 00330 /** 00331 * Alias for copy 00332 */ 00333 inline image& castFrom(const image& other) { 00334 copy(other); 00335 return *this; 00336 } 00337 00338 }; 00339 00340 // ========================================= 00341 // Define a palette type for indexed images 00342 // ========================================= 00343 00344 /** 00345 * Vector of rgbaPixel: used as a color palette 00346 */ 00347 typedef vector<rgbaPixel> palette; 00348 00349 /** 00350 * An empty vector used to denote an empty palette 00351 */ 00352 const palette emptyPalette; 00353 00354 } 00355 00356 00357 #endif 00358