last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998 - 2005 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 cvrChannel8.h 00044 * Contains the data structure to represent gray valued images 00045 * with one byte per pixel. 00046 * \author Pablo Alvarado 00047 * \date 09.04.1999 00048 * 00049 * $Id: cvrChannel8.h,v 1.7 2006/06/13 09:25:38 doerfler Exp $ 00050 */ 00051 00052 #ifndef _CVR_CHANNEL8_H_ 00053 #define _CVR_CHANNEL8_H_ 00054 00055 #include "cvrMatrix.h" 00056 #include "cvrTypes.h" 00057 00058 namespace cvr { 00059 00060 class channel; 00061 class image; 00062 00063 /** 00064 * A format for 8-bit channels. 00065 * 00066 * This class is identical to a matrix of bytes except for the method 00067 * castFrom(channel) 00068 * 00069 * The typical value range is between 0 and 255 (see cvr::image for more 00070 * information). 00071 * 00072 * @see cvr::image, cvr::channel 00073 * 00074 * @ingroup gAggregate 00075 * @ingroup gImageProcessing 00076 */ 00077 class channel8 : public matrix<ubyte> { 00078 public: 00079 /** 00080 * Default constructor creates an empty channel8 00081 */ 00082 channel8(); 00083 00084 /** 00085 * Create a connected \c rows x \c cols channel8 and leave all 00086 * elements uninitialized. 00087 * 00088 * @param rows number of rows of the channel8 00089 * @param cols number of columns of the channel8 00090 */ 00091 channel8(const int rows,const int cols); 00092 00093 /** 00094 * Create a connected \c size.y x \c size.x 00095 * channel8 and leave all elements uninitialized. 00096 * 00097 * @param size cvr::point with the size of the channel8 00098 * (size.x is the number of columns and 00099 * size.y the number of rows) 00100 */ 00101 channel8(const ipoint& size); 00102 00103 /** 00104 * Create a connected \c rows x \c cols channel8 and initializes 00105 * all elements with \a iniValue. 00106 * 00107 * @param rows number of rows of the channel8 00108 * @param cols number of columns of the channel8 00109 * @param iniValue all elements will be initialized with this value 00110 */ 00111 channel8(const int rows,const int cols,const ubyte& iniValue); 00112 00113 /** 00114 * Create a connected \c size.y x \c size.x 00115 * Channel8 and initializes all elements with \a iniValue 00116 * @param size cvr::point with the size of the channel8 00117 * (size.x is the number of columns and 00118 * size.y the number of rows) 00119 * @param iniValue all elements will be initialized with this value 00120 */ 00121 channel8(const ipoint& size,const ubyte& iniValue); 00122 00123 /** 00124 * Create a connected \c rows x \c cols Channel8 and initializes 00125 * all elements with the data pointed by \a data. The first 00126 * \a cols-elements of the data will be copied on the first row, 00127 * the next ones on the second row and so on. 00128 * 00129 * @param rows number of rows of the channel8 00130 * @param cols number of columns of the channel8 00131 * @param data pointer to the memory block with the data to be initialized 00132 * with. 00133 */ 00134 channel8(const int rows,const int cols,const ubyte data[]); 00135 00136 /** 00137 * Copy constructor. 00138 */ 00139 channel8(const channel8& other); 00140 00141 /** 00142 * Copy constructor. 00143 * 00144 * Create this channel8 as a connected copy of a submatrix of another 00145 * channel8. 00146 */ 00147 channel8(const channel8& other, 00148 const ipoint& from, 00149 const ipoint& to); 00150 00151 /** 00152 * Copy constructor. 00153 * 00154 * Create this channel8 as a connected copy of another channel8 00155 * for this const version, the data will be always copied! 00156 * It is also possible to create a copy of a subchannel of another 00157 * channel. 00158 * 00159 * @param other the channel8 to be copied. 00160 * @param fromRow initial row of the other channel8 to be copied 00161 * @param fromCol initial column of the other channel8 to be copied 00162 * @param toRow last row to be copied of the other channel8 00163 * @param toCol last column to be copied of the other channel8 00164 * 00165 * Example: 00166 * \code 00167 * cvr::channel8 m(4,6,0); // channel8 with 24 elements 00168 * // ... 00169 * // initialize channel8 with: 00170 * // 0 1 2 3 4 5 00171 * // 2 1 5 4 0 3 00172 * // 1 2 1 2 3 2 00173 * // 3 3 2 1 2 3 00174 * 00175 * cvr::channel8 sm(m,1,3,0,2) // last line will leat to 00176 * // following contents in sm: 00177 * // 1 2 3 00178 * // 1 5 4 00179 * // 2 1 2 00180 * \endcode 00181 * 00182 */ 00183 channel8(const channel8& other, 00184 const int fromRow, 00185 const int fromCol=0, 00186 const int toRow=MaxIndex, 00187 const int toCol=MaxIndex); 00188 00189 /** 00190 * Returns the name of this type. 00191 */ 00192 virtual const std::string& name() const; 00193 00194 /** 00195 * Create a clone of this channel8 00196 * @return a pointer to a copy of this matrix 00197 */ 00198 virtual channel8* clone() const; 00199 00200 /** 00201 * Create a new empty channel8 00202 * @return a pointer to a copy of this matrix 00203 */ 00204 virtual channel8* newInstance() const; 00205 00206 /** 00207 * Compute the sum of all elements in the channel 00208 */ 00209 int computeSumOfElements() const; 00210 00211 /** 00212 * Copy the \a other channel by casting each of its elements. 00213 * 00214 * The elements of the channel will be multiplied by 255 if no 00215 * other %parameter but the channel is given.. 00216 * 00217 * @param other the channel to be cast from 00218 * 00219 * @param minToBlack if minToBlack is true, a linear gray-valued 00220 * tranformation will be applied, which maps the minimal value in 00221 * the channel to zero. If false, the value zero will be mapped 00222 * to zero. 00223 * 00224 * @param maxToWhite if maxToWhite is true, a linear gray-valued 00225 * transformation will be applied, which maps the maximal value in 00226 * the channel to 255. If false, the value 1.0f will be mapped to 00227 * 255. 00228 * 00229 * @return a reference to this channel 00230 * Example: 00231 * \code 00232 * cvr::channel matA(10,10,1); // a channel 00233 * cvr::channel8 matB; // a channel8 00234 * 00235 * matB.castFrom(matA); // this will copy matA in matB!! 00236 * // and all elements will have 255 00237 * \endcode */ 00238 channel8& castFrom(const channel& other, 00239 const bool minToBlack = false, 00240 const bool maxToWhite = false); 00241 00242 /** 00243 * Cast the image to an channel8. 00244 * 00245 * It extracts the intensity channel of the image, defined as 00246 * (R+G+B)/3, where R, G, and B are the red, green and blue components 00247 * of the pixel. 00248 * 00249 * The elements of the resulting channel will be between 0 (black) and 00250 * 255 (white). 00251 * 00252 * @param other the image to be cast 00253 * @return a reference to this channel 00254 */ 00255 channel8& castFrom(const image& other); 00256 00257 /** 00258 * Copy the \a other matrix by casting each of its elements 00259 * 00260 * @param other The matrix to be cast 00261 * @return a reference to this channel 00262 */ 00263 template<class U> 00264 inline channel8& castFrom(const matrix<U>& other); 00265 00266 /** 00267 * Apply a gray valued transformation which maps the given intervall to 00268 * [0,255] (default) or the explicitly given "destination" interval 00269 * 00270 * @param minVal the lower limit of the original data interval 00271 * @param maxVal the higher limit of the original data interval 00272 * @param minDest the lower limit of the mapped interval (default 0) 00273 * @param maxDest the higher limit of the mapped interval (default 255) 00274 * @return a reference to this object 00275 * 00276 * For example, if you want to map the interval [20,200] to 00277 * the "usual" interval [0,255] just use one of following methods: 00278 * 00279 * \code 00280 * cvr::channel8 chnl; 00281 * // ... 00282 * chnl.mapLinear(20,200,0,255); // map [20,200] to [0,255] 00283 * // this is equivalent to (due to default "destination" interval) 00284 * chnl.mapLinear(20,200); 00285 * \endcode 00286 * 00287 * Not that you can use this method to "invert" your gray values with 00288 * \code 00289 * chnl.mapLinear(0,255,255,0); // map [0,255] to [255,0] 00290 * // this is equivalent to (due to default "destination" interval) 00291 * chnl.mapLinear(255,0); 00292 * \endcode 00293 * 00294 */ 00295 channel8& mapLinear(const ubyte& minVal, const ubyte& maxVal, 00296 const ubyte& minDest=0, const ubyte& maxDest=255); 00297 }; 00298 00299 template<class U> 00300 inline channel8& channel8::castFrom(const matrix<U>& other) { 00301 matrix<value_type>::castFrom(other); 00302 return *this; 00303 } 00304 00305 } 00306 00307 00308 #endif 00309