latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiImage.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 09.04.99 00030 * revisions ..: $Id: ltiImage.h,v 1.6 2006/02/08 11:18:43 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_IMAGE_H_ 00034 #define _LTI_IMAGE_H_ 00035 00036 #include "ltiMatrix.h" 00037 #include "ltiTypes.h" 00038 #include "ltiRGBPixel.h" 00039 00040 namespace lti { 00041 class channel8; 00042 class channel; 00043 00044 /** 00045 * The one and only RGB-image format. 00046 * 00047 * This class is an specialization of a matrix of lti::rgbPixel. 00048 * 00049 * The concept for color images and gray valued images in the LTI-Lib is 00050 * simple: they are specializations of the class lti::matrix. 00051 * 00052 * Several aspects must however be clarified. The rows of the matrix will 00053 * represent horizontal lines in the image, and the columns vertical ones. 00054 * The row with index zero will be the row at the top of the image. The 00055 * column with row zero is the one at the left of the image. This means 00056 * that the used coordinate system for the position of a pixel is 00057 * "left-handed": the origin is situated at the top-left corner of the 00058 * image, the x-coordinate gives the position in the horizontal axis and 00059 * the y-coordinate the position in the vertical axis. With other words, 00060 * the y coordinate give the row and x the column of the matrix. 00061 * This fact is important to remember when accessing the image elements: 00062 * 00063 * \code 00064 * image img; // our image 00065 * if (img.at(y,x) == img[y][x] == img.at(point(x,y))) { 00066 * cout << "This is always true!"; 00067 * } else { 00068 * cout << "ERROR: it's imposible to come here"; 00069 * exit 1; 00070 * } 00071 * \endcode 00072 * 00073 * The gray valued channels lti::channel and lti::channel8 differ on 00074 * the type and valid value ranges of their elements. The former 00075 * accepts floating point values, with a default value range from 00076 * 0.0 to 1.0. Many algorithms produce other values with specific 00077 * meanings like angles or gradients, but using the default range you can 00078 * assume 0.0 as a representation for black and 1.0 for white. 00079 * 00080 * The lti::channel8 is a much smaller representation but allows 00081 * only integer values between 0 and 255, fact that can be advantageous 00082 * in many algorithms. Here 0 usually means black and 255 white. 00083 * 00084 * The lti::image as lti::matrix<lti::rgbPixel> allows the representation of 00085 * true-color images, i.e. images with pixels that can be chosen from a 00086 * palette of more than 16 million colors. 00087 * 00088 * @see lti::matrix for a reference to all inherited methods. 00089 * 00090 * @ingroup gAggregate 00091 * @ingroup gColor 00092 * @ingroup gImageProcessing 00093 */ 00094 class image : public matrix<rgbPixel> { 00095 public: 00096 /** 00097 * default constructor creates an empty image 00098 */ 00099 image(); 00100 00101 /** 00102 * this constructor creates a connected <code>rows x cols</code> image 00103 * and initializes all elements with <code>iniValue</code> 00104 * @param rows number of rows of the image 00105 * @param cols number of columns of the image 00106 * @param iniValue all elements will be initialized with this value 00107 */ 00108 image(const int& rows,const int& cols, 00109 const rgbPixel& iniValue = rgbPixel()); 00110 00111 /** 00112 * this constructor creates a connected <code>rows x cols</code> image 00113 * and initializes all elements with the data pointed by 00114 * <code>data</code>. The first <code>cols</code>-elements of the data 00115 * will be copied on the first row, the next ones on the second row and 00116 * so on. 00117 * @param rows number of rows of the image 00118 * @param cols number of columns of the image 00119 * @param data pointer to the memory block with the data to be initialized 00120 * with. 00121 */ 00122 image(const int& rows,const int& cols,const rgbPixel data[]); 00123 00124 /** 00125 * this constructor creates a connected <code>size.y x size.x</code> 00126 * image and initializes all elements with <code>iniValue</code> 00127 * @param size lti::point with the size of the image 00128 * (size.x is the number of columns and 00129 * size.y the number of rows) 00130 * @param iniValue all elements will be initialized with this value 00131 */ 00132 image(const ipoint& size,const rgbPixel& iniValue = rgbPixel()); 00133 00134 /** 00135 * copy constructor. 00136 * 00137 * create this image as a connected copy of another image 00138 * for this const version, the data will be always copied! 00139 * It is also possible to create a copy of a subimage of another image. 00140 * 00141 * @param other the image to be copied. 00142 * @param fromRow initial row of the other image to be copied 00143 * @param toRow last row to be copied of the other image 00144 * @param fromCol initial column of the other image to be copied 00145 * @param toCol last column to be copied of the other image 00146 * 00147 * Example: 00148 * \code 00149 * lti::image m(4,6,0); // image with 24 elements 00150 * // ... 00151 * // initialize image with: 00152 * // 0 1 2 3 4 5 00153 * // 2 1 5 4 0 3 00154 * // 1 2 1 2 3 2 00155 * // 3 3 2 1 2 3 00156 * 00157 * lti::image sm(m,1,3,0,2) // this line will lead to the 00158 * // following contents for sm: 00159 * // 1 2 3 00160 * // 1 5 4 00161 * // 2 1 2 00162 * \endcode 00163 * 00164 */ 00165 image(const image& other, 00166 const int& fromRow=0,const int& toRow=MaxInt32, 00167 const int& fromCol=0,const int& toCol=MaxInt32); 00168 00169 /** 00170 * copy constructor (reference to a subimage). 00171 * 00172 * creates subimage of another image. 00173 * 00174 * if <code>copyData == true</code>, the new object has its own data 00175 * (equivalent to previous copy constructor). 00176 * 00177 * if <code>copyData == false</code>, the new object has references to 00178 * the other image, which means that the data is not necessarily 00179 * consecutive. (This will not be a connected but a lined image) 00180 * 00181 * Those algorithms which use direct access to the image memory block 00182 * should check first if the memory lies in a consecutive block! 00183 * (see getMode()) 00184 * 00185 * @param copyData should the data of the other image be copied or not 00186 * @param other the image with the original data 00187 * @param fromRow initial row of the other image to be copied 00188 * @param toRow last row to be copied of the other image 00189 * @param fromCol initial column of the other image to be copied 00190 * @param toCol last column to be copied of the other image 00191 */ 00192 image(const bool& copyData, image& other, 00193 const int& fromRow=0,const int& toRow=MaxInt32, 00194 const int& fromCol=0,const int& toCol=MaxInt32); 00195 00196 /** 00197 * If \a init is true this constructor is equivalent to calling 00198 * image(const int& rows, const int& cols), and thus initializing 00199 * all elements with T(). However, in some cases the elements need 00200 * not be initialized during construction, since complex 00201 * initializion is required. Especially for large matrices, the 00202 * unnecessary constructor initialization is very time consuming. 00203 * 00204 * If \a init is false, memory is allocated but no initialization 00205 * takes place. Thus the following is equivalent: 00206 * \code 00207 * image a(false,100,100); 00208 * 00209 * image a; 00210 * a.resize(100,100,0,false,false); 00211 * \endcode 00212 * 00213 * @param init initialize image or not 00214 * @param rows number of rows of the image 00215 * @param cols number of columns of the image 00216 */ 00217 image(const bool& init, const int& rows, const int& cols); 00218 00219 /** 00220 * If \a init is true this constructor is equivalent to calling 00221 * image(const point& size), and thus initializing 00222 * all elements with T(). However, in some cases the elements need 00223 * not be initialized during construction, since complex 00224 * initializion is required. Especially for large matrices, the 00225 * unnecessary constructor initialization is very time consuming. 00226 * 00227 * If \a init is false, memory is allocated but no initialization 00228 * takes place. Thus the following is equivalent: 00229 * \code 00230 * image a(false,point(100,100)); 00231 * 00232 * image a; 00233 * a.resize(100,100,0,false,false); 00234 * \endcode 00235 * 00236 * @param init initialize image or not 00237 * @param size new size 00238 */ 00239 image(const bool& init, const ipoint& size); 00240 00241 /** 00242 * create a clone of this image 00243 * @return a pointer to a copy of this image 00244 */ 00245 virtual mathObject* clone() const; 00246 00247 /** 00248 * return the name of this type 00249 */ 00250 virtual const char* getTypeName() const; 00251 00252 00253 /** 00254 * cast from the <code>other</code> channel8. 00255 * For the transformation it assumes the channel8 as a gray valued 00256 * channel where 0 means black and 255 means white. 00257 * 00258 * @param other the channel8 to be casted 00259 * @return a reference to this image 00260 * Example: 00261 * \code 00262 * lti::channel8 matA(10,10,255); // a channel8 00263 * lti::image matB; // an image 00264 * 00265 * matB.castFrom(matA); // this will copy matA in matB!! 00266 * // and all elements will have 00267 * // rgbPixel(255,255,255) 00268 * \endcode 00269 */ 00270 image& castFrom(const channel8& other); 00271 00272 /** 00273 * cast from the <code>other</code> channel. 00274 * For the transformation it assumes the channel as a gray valued 00275 * channel where 0 means black and 1.0f means white. All other 00276 * values will be clipped (less than zero to zero and more than 1.0 to 1.0) 00277 * 00278 * @param other the channel8 to be casted 00279 * @param minToBlack if minToBlack is true, a linear gray-valued 00280 * tranformation will be applied, which maps the minimal value in 00281 * the channel to (0,0,0). If false, the value zero will be mapped 00282 * to zero. 00283 * @param maxToWhite if maxToWhite is true, a linear gray-valued 00284 * transformation will be applied, which maps the maximal value in 00285 * the channel to (255,255,255). If false, the value 1.0f will be 00286 * mapped to 255. 00287 * @return a reference to this image 00288 * Example: 00289 * \code 00290 * lti::channel matA(10,10,1.0f); // a channel 00291 * lti::image matB; // an image 00292 * 00293 * matB.castFrom(matA); // this will copy matA in matB!! 00294 * // and all elements will have 00295 * // rgbPixel(255,255,255) 00296 * \endcode 00297 */ 00298 image& castFrom(const channel& other, 00299 const bool minToBlack = false, 00300 const bool maxToWhite = false); 00301 00302 }; 00303 00304 /** 00305 * a format for float channels. 00306 * 00307 * This class is identical to a matrix of floats except for the method 00308 * castFrom(channel8). 00309 * 00310 * The typical value range is between 0.0f and 1.0f (see lti::image for more 00311 * information). 00312 * 00313 * @see lti::image, lti::channel8 00314 * 00315 * @ingroup gAggregate 00316 * @ingroup gImageProcessing 00317 */ 00318 class channel : public matrix<float> { 00319 public: 00320 /** 00321 * default constructor creates an empty channel 00322 */ 00323 channel(); 00324 00325 /** 00326 * this constructor creates a connected <code>rows x cols</code> channel 00327 * and initializes all elements with <code>iniValue</code> 00328 * @param rows number of rows of the channel 00329 * @param cols number of columns of the channel 00330 * @param iniValue all elements will be initialized with this value 00331 */ 00332 channel(const int& rows,const int& cols,const float& iniValue = float()); 00333 00334 /** 00335 * this constructor creates a connected <code>rows x cols</code> channel 00336 * and initializes all elements with the data pointed by 00337 * <code>data</code>. The first <code>cols</code>-elements of the data 00338 * will be copied on the first row, the next ones on the second row and 00339 * so on. 00340 * @param rows number of rows of the channel 00341 * @param cols number of columns of the channel 00342 * @param data pointer to the memory block with the data to be initialized 00343 * with. 00344 */ 00345 channel(const int& rows,const int& cols,const float data[]); 00346 00347 /** 00348 * this constructor creates a connected <code>size.y x size.x</code> 00349 * channel and initializes all elements with <code>iniValue</code> 00350 * @param size lti::point with the size of the channel 00351 * (size.x is the number of columns and 00352 * size.y the number of rows) 00353 * @param iniValue all elements will be initialized with this value 00354 */ 00355 channel(const ipoint& size,const float& iniValue = float()); 00356 00357 /** 00358 * copy constructor. 00359 * 00360 * create this channel as a connected copy of another channel 00361 * for this const version, the data will be always copied! 00362 * It is also possible to create a copy of a subchannel of another channel. 00363 * 00364 * @param other the channel to be copied. 00365 * @param fromRow initial row of the other channel to be copied 00366 * @param toRow last row to be copied of the other channel 00367 * @param fromCol initial column of the other channel to be copied 00368 * @param toCol last column to be copied of the other channel 00369 * 00370 * Example: 00371 * \code 00372 * lti::channel m(4,6,0); // channel with 24 elements 00373 * // ... 00374 * // initialize channel with: 00375 * // 0 1 2 3 4 5 00376 * // 2 1 5 4 0 3 00377 * // 1 2 1 2 3 2 00378 * // 3 3 2 1 2 3 00379 * 00380 * lti::channel sm(m,1,3,0,2) // this line will lead to the 00381 * // following contents for sm: 00382 * // 1 2 3 00383 * // 1 5 4 00384 * // 2 1 2 00385 * \endcode 00386 * 00387 */ 00388 channel(const channel& other, 00389 const int& fromRow=0,const int& toRow=MaxInt32, 00390 const int& fromCol=0,const int& toCol=MaxInt32); 00391 00392 /** 00393 * copy constructor (reference to a subchannel). 00394 * 00395 * creates subchannel of another channel. 00396 * 00397 * if <code>copyData == true</code>, the new object has its own data 00398 * (equivalent to previous copy constructor). 00399 * 00400 * if <code>copyData == false</code>, the new object has references to 00401 * the other channel, which means that the data is not necessarily 00402 * consecutive. (This will not be a connected but a lined channel) 00403 * 00404 * Those algorithms which use direct access to the channel memory block 00405 * should check first if the memory lies in a consecutive block! 00406 * (see getMode()) 00407 * 00408 * @param copyData should the data of the other channel be copied or not 00409 * @param other the channel with the original data 00410 * @param fromRow initial row of the other channel to be copied 00411 * @param toRow last row to be copied of the other channel 00412 * @param fromCol initial column of the other channel to be copied 00413 * @param toCol last column to be copied of the other channel 00414 */ 00415 channel(const bool& copyData, channel& other, 00416 const int& fromRow=0,const int& toRow=MaxInt32, 00417 const int& fromCol=0,const int& toCol=MaxInt32); 00418 00419 /** 00420 * If \a init is true this constructor is equivalent to calling 00421 * channel(const int& rows, const int& cols), and thus initializing 00422 * all elements with T(). However, in some cases the elements need 00423 * not be initialized during construction, since complex 00424 * initializion is required. Especially for large matrices, the 00425 * unnecessary constructor initialization is very time consuming. 00426 * 00427 * If \a init is false, memory is allocated but no initialization 00428 * takes place. Thus the following is equivalent: 00429 * \code 00430 * channel a(false,100,100); 00431 * 00432 * channel a; 00433 * a.resize(100,100,0,false,false); 00434 * \endcode 00435 * 00436 * @param init initialize channel or not 00437 * @param rows number of rows of the channel 00438 * @param cols number of columns of the channel 00439 */ 00440 channel(const bool& init, const int& rows, const int& cols); 00441 00442 /** 00443 * If \a init is true this constructor is equivalent to calling 00444 * channel(const int& rows, const int& cols), and thus initializing 00445 * all elements with T(). However, in some cases the elements need 00446 * not be initialized during construction, since complex 00447 * initializion is required. Especially for large matrices, the 00448 * unnecessary constructor initialization is very time consuming. 00449 * 00450 * If \a init is false, memory is allocated but no initialization 00451 * takes place. Thus the following is equivalent: 00452 * \code 00453 * channel a(false,point(100,100)); 00454 * 00455 * channel a; 00456 * a.resize(100,100,0,false,false); 00457 * \endcode 00458 * 00459 * @param init initialize channel or not 00460 * @param size new size for the matrix (size.x columns, size.y rows) 00461 */ 00462 channel(const bool& init, const ipoint& size); 00463 00464 /** 00465 * create a clone of this channel 00466 * @return a pointer to a copy of this matrix 00467 */ 00468 virtual mathObject* clone() const; 00469 00470 /** 00471 * return the name of this type 00472 */ 00473 virtual const char* getTypeName() const; 00474 00475 /** 00476 * copy the <code>other</code> channel8 by casting each of its elements. 00477 * 00478 * The elements of the channel8 will be also multiplied by 1/255. 00479 * 00480 * @param other the channel8 to be casted 00481 * @return a reference to this channel 00482 * Example: 00483 * \code 00484 * lti::channel8 matA(10,10,255); // a channel8 00485 * lti::channel matB; // a channel 00486 * 00487 * matB.castFrom(matA); // this will copy matA in matB!! 00488 * // and all elements will have 1.0f 00489 * \endcode 00490 */ 00491 channel& castFrom(const channel8& other); 00492 00493 /** 00494 * cast the image to an channel. 00495 * It extracts the intensity channel of the image, defined as 00496 * (R+G+B)/3, where R, G, and B are the red, green and blue components 00497 * of the pixel. 00498 * 00499 * The elements of the resulting channel will be between 0.0f (black) and 00500 * 1.0f (white). 00501 * 00502 * @param other the image to be casted 00503 * @return a reference to this channel 00504 */ 00505 channel& castFrom(const image& other); 00506 00507 /** 00508 * Apply a gray valued transformation which maps the given intervall to 00509 * [0.0,1.0] (default) or the explicitly given "destination" interval 00510 * @param minVal the lower limit of the original data interval 00511 * @param maxVal the higher limit of the original data interval 00512 * @param minDest the lower limit of the mapped interval (default 0.0f) 00513 * @param maxDest the higher limit of the mapped interval (default 1.0f) 00514 * @return a reference to this object 00515 * 00516 * For example, if you want to map the interval [-1.0f,2.0f] to 00517 * the "usual" interval [0.0,1.0] just use one of following methods: 00518 * 00519 * \code 00520 * lti::channel chnl; 00521 * // ... 00522 * chnl.mapLinear(-1.0f,2.0f,0.0,1.0); // map [-1,2] to [0,1] 00523 * // this is equivalent to (due to default "destination" interval) 00524 * chnl.mapLinear(-1.0f,2.0f); 00525 * \endcode 00526 * 00527 * Not that you can use this method to "invert" your gray values with 00528 * \code 00529 * chnl.mapLinear(0.0f,1.0f,1,0f,0.0f); // map [0,1] to [1,0] 00530 * // this is equivalent to (due to default "destination" interval) 00531 * chnl.mapLinear(1.0f,0.0f); 00532 * \endcode 00533 * 00534 */ 00535 channel& mapLinear(const float& minVal, const float& maxVal, 00536 const float& minDest=0.0f, const float& maxDest=1.0f); 00537 00538 00539 /** 00540 * Apply a gray valued transformation which maps the given 00541 * intervall of the other channel into [0.0,1.0] (default) or the 00542 * explicitly given "destination" interval in this channel. 00543 * 00544 * @param other the other channel which values are to be mapped into 00545 * the new interval 00546 * @param minVal the lower limit of the original data interval 00547 * @param maxVal the higher limit of the original data interval 00548 * @param minDest the lower limit of the mapped interval (default 0.0f) 00549 * @param maxDest the higher limit of the mapped interval (default 1.0f) 00550 * @return a reference to this object 00551 * 00552 * For example, if you want to map the interval [-1.0f,2.0f] to 00553 * the "usual" interval [0.0,1.0] just use one of following methods: 00554 * 00555 * \code 00556 * lti::channel chnl; 00557 * // ... 00558 * chnl.mapLinear(-1.0f,2.0f,0.0,1.0); // map [-1,2] to [0,1] 00559 * // this is equivalent to (due to default "destination" interval) 00560 * chnl.mapLinear(-1.0f,2.0f); 00561 * \endcode 00562 * 00563 * Not that you can use this method to "invert" your gray values with 00564 * \code 00565 * chnl.mapLinear(0.0f,1.0f,1,0f,0.0f); // map [0,1] to [1,0] 00566 * // this is equivalent to (due to default "destination" interval) 00567 * chnl.mapLinear(1.0f,0.0f); 00568 * \endcode 00569 * */ 00570 channel& mapLinear(const channel& other, 00571 const float& minVal, const float& maxVal, 00572 const float& minDest=0.0f, const float& maxDest=1.0f); 00573 00574 /** 00575 * copy the <code>other</code> matrix by casting each of its elements 00576 * @param other The matrix to be casted 00577 * @return a reference to this channel 00578 */ 00579 template<class U> 00580 channel& castFrom(const matrix<U>& other) { 00581 matrix<value_type>::castFrom(other); 00582 return *this; 00583 }; 00584 }; 00585 00586 /** 00587 * a format for 8-bit-channels. 00588 * 00589 * This class is identical to a matrix of bytes except for the method 00590 * castFrom(channel) 00591 * 00592 * The typical value range is between 0 and 255 (see lti::image for more 00593 * information). 00594 * 00595 * @see lti::image, lti::channel 00596 * 00597 * @ingroup gAggregate 00598 * @ingroup gImageProcessing 00599 */ 00600 class channel8 : public matrix<ubyte> { 00601 public: 00602 /** 00603 * default constructor creates an empty channel8 00604 */ 00605 channel8(); 00606 00607 /** 00608 * this constructor creates a connected <code>rows x cols</code> Channel8 00609 * and initializes all elements with <code>iniValue</code> 00610 * @param rows number of rows of the channel8 00611 * @param cols number of columns of the channel8 00612 * @param iniValue all elements will be initialized with this value 00613 */ 00614 channel8(const int& rows,const int& cols,const ubyte& iniValue = ubyte()); 00615 00616 /** 00617 * this constructor creates a connected <code>rows x cols</code> Channel8 00618 * and initializes all elements with the data pointed by 00619 * <code>data</code>. The first <code>cols</code>-elements of the data 00620 * will be copied on the first row, the next ones on the second row and 00621 * so on. 00622 * 00623 * @param rows number of rows of the channel8 00624 * @param cols number of columns of the channel8 00625 * @param data pointer to the memory block with the data to be initialized 00626 * with. 00627 */ 00628 channel8(const int& rows,const int& cols,const ubyte data[]); 00629 00630 /** 00631 * this constructor creates a connected <code>size.y x size.x</code> 00632 * Channel8 and initializes all elements with <code>iniValue</code> 00633 * @param size lti::point with the size of the channel8 00634 * (size.x is the number of columns and 00635 * size.y the number of rows) 00636 * @param iniValue all elements will be initialized with this value 00637 */ 00638 channel8(const ipoint& size,const ubyte& iniValue = ubyte()); 00639 00640 /** 00641 * copy constructor. 00642 * 00643 * create this channel8 as a connected copy of another channel8 00644 * for this const version, the data will be always copied! 00645 * It is also possible to create a copy of a subchannel of another 00646 * channel. 00647 * 00648 * @param other the channel8 to be copied. 00649 * @param fromRow initial row of the other channel8 to be copied 00650 * @param toRow last row to be copied of the other channel8 00651 * @param fromCol initial column of the other channel8 to be copied 00652 * @param toCol last column to be copied of the other channel8 00653 * 00654 * Example: 00655 * \code 00656 * lti::channel8 m(4,6,0); // channel8 with 24 elements 00657 * // ... 00658 * // initialize channel8 with: 00659 * // 0 1 2 3 4 5 00660 * // 2 1 5 4 0 3 00661 * // 1 2 1 2 3 2 00662 * // 3 3 2 1 2 3 00663 * 00664 * lti::channel8 sm(m,1,3,0,2) // last line will leat to 00665 * // following contents in sm: 00666 * // 1 2 3 00667 * // 1 5 4 00668 * // 2 1 2 00669 * \endcode 00670 * 00671 */ 00672 channel8(const channel8& other, 00673 const int& fromRow=0,const int& toRow=MaxInt32, 00674 const int& fromCol=0,const int& toCol=MaxInt32); 00675 00676 /** 00677 * copy constructor (reference to a subchannel8). 00678 * 00679 * creates subchannel8 of another channel8. 00680 * 00681 * if <code>copyData == true</code>, the new object has its own data 00682 * (equivalent to previous copy constructor). 00683 * 00684 * if <code>copyData == false</code>, the new object has references to 00685 * the other channel8, which means that the data is not necessarily 00686 * consecutive. (This will not be a connected but a lined channel8) 00687 * 00688 * Those algorithms which use direct access to the channel8 memory block 00689 * should check first if the memory lies in a consecutive block! 00690 * (see getMode()) 00691 * 00692 * @param copyData should the data of the other channel8 be copied or not 00693 * @param other the channel with the original data 00694 * @param fromRow initial row of the other channel8 to be copied 00695 * @param toRow last row to be copied of the other channel8 00696 * @param fromCol initial column of the other channel8 to be copied 00697 * @param toCol last column to be copied of the other channel8 00698 */ 00699 channel8(const bool& copyData, channel8& other, 00700 const int& fromRow=0,const int& toRow=MaxInt32, 00701 const int& fromCol=0,const int& toCol=MaxInt32); 00702 00703 /** 00704 * If \a init is true this constructor is equivalent to calling 00705 * channel8(const int& rows, const int& cols), and thus initializing 00706 * all elements with T(). However, in some cases the elements need 00707 * not be initialized during construction, since complex 00708 * initializion is required. Especially for large matrices, the 00709 * unnecessary constructor initialization is very time consuming. 00710 * 00711 * If \a init is false, memory is allocated but no initialization 00712 * takes place. Thus the following is equivalent: 00713 * \code 00714 * channel8 a(false,100,100); 00715 * 00716 * channel8 a; 00717 * a.resize(100,100,0,false,false); 00718 * \endcode 00719 * 00720 * @param init initialize channel8 or not 00721 * @param rows number of rows of the channel8 00722 * @param cols number of columns of the channel8 00723 */ 00724 channel8(const bool& init, const int& rows, const int& cols); 00725 00726 /** 00727 * If \a init is true this constructor is equivalent to calling 00728 * channel(const int& rows, const int& cols), and thus initializing 00729 * all elements with T(). However, in some cases the elements need 00730 * not be initialized during construction, since complex 00731 * initializion is required. Especially for large matrices, the 00732 * unnecessary constructor initialization is very time consuming. 00733 * 00734 * If \a init is false, memory is allocated but no initialization 00735 * takes place. Thus the following is equivalent: 00736 * \code 00737 * channel a(false,point(100,100)); 00738 * 00739 * channel a; 00740 * a.resize(100,100,0,false,false); 00741 * \endcode 00742 * 00743 * @param init initialize channel or not 00744 * @param size new size for the matrix (size.x columns, size.y rows) 00745 */ 00746 channel8(const bool& init, const ipoint& size); 00747 00748 /** 00749 * create a clone of this channel 00750 * @return a pointer to a copy of this matrix 00751 */ 00752 virtual mathObject* clone() const; 00753 00754 /** 00755 * return the name of this type 00756 */ 00757 virtual const char* getTypeName() const; 00758 00759 int sumOfElements() const; 00760 00761 /** 00762 * copy the <code>other</code> channel by casting each of its elements. 00763 * 00764 * The elements of the channel will be multiplied by 255 if no 00765 * other %parameter but the channel is given.. 00766 * 00767 * @param other the channel to be casted from 00768 * 00769 * @param minToBlack if minToBlack is true, a linear gray-valued 00770 * tranformation will be applied, which maps the minimal value in 00771 * the channel to zero. If false, the value zero will be mapped 00772 * to zero. 00773 * 00774 * @param maxToWhite if maxToWhite is true, a linear gray-valued 00775 * transformation will be applied, which maps the maximal value in 00776 * the channel to 255. If false, the value 1.0f will be mapped to 00777 * 255. 00778 * 00779 * @return a reference to this channel 00780 * Example: 00781 * \code 00782 * lti::channel matA(10,10,1); // a channel 00783 * lti::channel8 matB; // a channel8 00784 * 00785 * matB.castFrom(matA); // this will copy matA in matB!! 00786 * // and all elements will have 255 00787 * \endcode */ 00788 channel8& castFrom(const channel& other, 00789 const bool minToBlack = false, 00790 const bool maxToWhite = false); 00791 00792 /** 00793 * cast the image to an channel8. 00794 * It extracts the intensity channel of the image, defined as 00795 * (R+G+B)/3, where R, G, and B are the red, green and blue components 00796 * of the pixel. 00797 * 00798 * The elements of the resulting channel will be between 0 (black) and 00799 * 255 (white). 00800 * 00801 * @param other the image to be casted 00802 * @return a reference to this channel 00803 */ 00804 channel8& castFrom(const image& other); 00805 00806 /** 00807 * copy the <code>other</code> matrix by casting each of its elements 00808 * @param other The matrix to be casted 00809 * @return a reference to this channel 00810 */ 00811 template<class U> 00812 channel8& castFrom(const matrix<U>& other) { 00813 matrix<value_type>::castFrom(other); 00814 return *this; 00815 }; 00816 00817 }; 00818 00819 /** 00820 * a format for signed 32-bit-channels. 00821 * 00822 * This class is identical to a matrix of integers except for the method 00823 * castFrom(channel) 00824 * 00825 * @see lti::image 00826 * 00827 * @ingroup gAggregate 00828 */ 00829 class channel32 : public matrix<int32> { 00830 public: 00831 /** 00832 * default constructor creates an empty channel32 00833 */ 00834 channel32(); 00835 00836 /** 00837 * this constructor creates a connected <code>rows x cols</code> Channel32 00838 * and initializes all elements with <code>iniValue</code> 00839 * @param rows number of rows of the channel32 00840 * @param cols number of columns of the channel32 00841 * @param iniValue all elements will be initialized with this value 00842 */ 00843 channel32(const int& rows,const int& cols,const int& iniValue = int()); 00844 00845 /** 00846 * this constructor creates a connected <code>rows x cols</code> Channel32 00847 * and initializes all elements with the data pointed by 00848 * <code>data</code>. The first <code>cols</code>-elements of the data 00849 * will be copied on the first row, the next ones on the second row and 00850 * so on. 00851 * @param rows number of rows of the channel32 00852 * @param cols number of columns of the channel32 00853 * @param data pointer to the memory block with the data to be initialized 00854 * with. 00855 */ 00856 channel32(const int& rows,const int& cols,const int data[]); 00857 00858 /** 00859 * this constructor creates a connected <code>size.y x size.x</code> 00860 * Channel32 and initializes all elements with <code>iniValue</code> 00861 * @param size lti::point with the size of the channel32 00862 * (size.x is the number of columns and 00863 * size.y the number of rows) 00864 * @param iniValue all elements will be initialized with this value 00865 */ 00866 channel32(const ipoint& size,const int& iniValue = int()); 00867 00868 /** 00869 * copy constructor. 00870 * 00871 * create this channel32 as a connected copy of another channel32 00872 * for this const version, the data will be always copied! 00873 * It is also possible to create a copy of a subchannel of another 00874 * channel. 00875 * 00876 * @param other the channel32 to be copied. 00877 * @param fromRow initial row of the other channel32 to be copied 00878 * @param toRow last row to be copied of the other channel32 00879 * @param fromCol initial column of the other channel32 to be copied 00880 * @param toCol last column to be copied of the other channel32 00881 * 00882 * Example: 00883 * \code 00884 * lti::channel32 m(4,6,0); // integer channel32 with 25 elements 00885 * // ... 00886 * // initialize Channel32 with: 00887 * // 0 1 2 3 4 5 00888 * // 2 1 5 4 0 3 00889 * // 1 2 1 2 3 2 00890 * // 3 3 2 1 2 3 00891 * 00892 * lti::channel32<int> sm(m,1,3,0,2) // last line will leat to 00893 * // following contents in sm: 00894 * // 1 2 3 00895 * // 1 5 4 00896 * // 2 1 2 00897 * \endcode 00898 * 00899 */ 00900 channel32(const channel32& other, 00901 const int& fromRow=0,const int& toRow=MaxInt32, 00902 const int& fromCol=0,const int& toCol=MaxInt32); 00903 00904 /** 00905 * copy constructor (reference to a subchannel32). 00906 * 00907 * creates subchannel32 of another channel32. 00908 * 00909 * if <code>copyData == true</code>, the new object has its own data 00910 * (equivalent to previous copy constructor). 00911 * 00912 * if <code>copyData == false</code>, the new object has references to 00913 * the other channel32, which means that the data is not necessarily 00914 * consecutive. (This will not be a connected but a lined channel32) 00915 * 00916 * Those algorithms which use direct access to the channel32 memory block 00917 * should check first if the memory lies in a consecutive block! 00918 * (see getMode()) 00919 * 00920 * @param copyData should the data of the other channel32 be copied or not 00921 * @param other the channel with the original data 00922 * @param fromRow initial row of the other channel32 to be copied 00923 * @param toRow last row to be copied of the other channel32 00924 * @param fromCol initial column of the other channel32 to be copied 00925 * @param toCol last column to be copied of the other channel32 00926 */ 00927 channel32(const bool& copyData, channel32& other, 00928 const int& fromRow=0,const int& toRow=MaxInt32, 00929 const int& fromCol=0,const int& toCol=MaxInt32); 00930 00931 /** 00932 * If \a init is true this constructor is equivalent to calling 00933 * channel8(const int& rows, const int& cols), and thus initializing 00934 * all elements with T(). However, in some cases the elements need 00935 * not be initialized during construction, since complex 00936 * initializion is required. Especially for large matrices, the 00937 * unnecessary constructor initialization is very time consuming. 00938 * 00939 * If \a init is false, memory is allocated but no initialization 00940 * takes place. Thus the following is equivalent: 00941 * \code 00942 * channel8 a(false,100,100); 00943 * 00944 * channel8 a; 00945 * a.resize(100,100,0,false,false); 00946 * \endcode 00947 * 00948 * @param init initialize channel8 or not 00949 * @param rows number of rows of the channel8 00950 * @param cols number of columns of the channel8 00951 */ 00952 channel32(const bool& init, const int& rows, const int& cols); 00953 00954 /** 00955 * If \a init is true this constructor is equivalent to calling 00956 * channel(const int& rows, const int& cols), and thus initializing 00957 * all elements with T(). However, in some cases the elements need 00958 * not be initialized during construction, since complex 00959 * initializion is required. Especially for large matrices, the 00960 * unnecessary constructor initialization is very time consuming. 00961 * 00962 * If \a init is false, memory is allocated but no initialization 00963 * takes place. Thus the following is equivalent: 00964 * \code 00965 * channel a(false,point(100,100)); 00966 * 00967 * channel a; 00968 * a.resize(100,100,0,false,false); 00969 * \endcode 00970 * 00971 * @param init initialize channel or not 00972 * @param size new size for the matrix (size.x columns, size.y rows) 00973 */ 00974 channel32(const bool& init, const ipoint& size); 00975 00976 /** 00977 * create a clone of this channel 00978 * @return a pointer to a copy of this matrix 00979 */ 00980 virtual mathObject* clone() const; 00981 00982 /** 00983 * return the name of this type 00984 */ 00985 virtual const char* getTypeName() const; 00986 00987 /** 00988 * copy the <code>other</code> matrix by casting each of its elements 00989 * @param other The matrix to be casted 00990 * @return a reference to this channel 00991 */ 00992 template<class U> 00993 channel32& castFrom(const matrix<U>& other) { 00994 matrix<value_type>::castFrom(other); 00995 return *this; 00996 }; 00997 }; 00998 00999 // ========================================= 01000 // Define a palette type for indexed images 01001 // ========================================= 01002 01003 /** 01004 * Vector of rgbPixel: used as a color palette 01005 */ 01006 typedef vector<rgbPixel> palette; 01007 01008 /** 01009 * An empty vector used to denote an empty palette 01010 */ 01011 const palette emptyPalette; 01012 01013 } 01014 01015 01016 #endif