latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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-Lib: Image Processing and Computer Vision Library 00026 * file .......: ltiBayerDemosaicing.h 00027 * authors ....: Arnd Hannemann 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 28.10.2004 00030 * revisions ..: $Id: ltiBayerDemosaicing.h,v 1.4 2006/12/31 22:29:55 alvarado Exp $ 00031 */ 00032 00033 #ifndef _LTI_BAYER_DEMOSAICING_H_ 00034 #define _LTI_BAYER_DEMOSAICING_H_ 00035 00036 00037 00038 #include "ltiMatrix.h" 00039 #include "ltiVector.h" 00040 00041 #include "ltiTransform.h" 00042 00043 namespace lti { 00044 /** 00045 * This functor makes a color interpolation of common 00046 * BAYER Patterns used in digital cameras. 00047 */ 00048 class bayerDemosaicing : public transform { 00049 public: 00050 00051 /** 00052 * In a Bayer pattern there are three different color filters 00053 * used in front of the actual pixels of the CCD chip. They have 00054 * the colors red(R), green(G), and blue(B). On a 2x2 grid of 00055 * pixels two are always green and these always lie on a 00056 * diagonal. This results in four possible constellations for 00057 * the three colors. 00058 * 00059 * If NoBayer is chosen then no demosaicing takes place. This 00060 * makes sense for mono cameras or to avoid demosaicing. 00061 */ 00062 enum eBayerPattern { 00063 NoBayer, /**< no Bayer pattern used, no demosaicing, mono camera */ 00064 RGGB, /**< Red, Green in first row, Green, Blue in second */ 00065 BGGR, /**< Blue, Green in first row, Green, Red in second */ 00066 GBRG, /**< Green, Blue in first row, Red, Green in second */ 00067 GRBG /**< Green, Red in first row, Blue, Green in second */ 00068 }; 00069 00070 /** 00071 * Enumeration of supported interpolation methods 00072 */ 00073 enum eBayerMethod { 00074 Simple, /**< Do averaging of two green values per pixel */ 00075 NearestNeighbor /**< Take the nearest (vertical) green value for each 00076 pixel */ 00077 }; 00078 00079 00080 /** 00081 * The parameters for the class bayerDemosaicing 00082 */ 00083 class parameters : public transform::parameters { 00084 public: 00085 00086 00087 /** 00088 * Default constructor 00089 */ 00090 parameters(); 00091 00092 /** 00093 * Copy constructor 00094 * @param other the parameters object to be copied 00095 */ 00096 parameters(const parameters& other); 00097 00098 /** 00099 * Destructor 00100 */ 00101 ~parameters(); 00102 00103 /** 00104 * Returns name of this type 00105 */ 00106 const char* getTypeName() const; 00107 00108 /** 00109 * Copy the contents of a parameters object 00110 * @param other the parameters object to be copied 00111 * @return a reference to this parameters object 00112 */ 00113 parameters& copy(const parameters& other); 00114 00115 /** 00116 * Copy the contents of a parameters object 00117 * @param other the parameters object to be copied 00118 * @return a reference to this parameters object 00119 */ 00120 parameters& operator=(const parameters& other); 00121 00122 00123 /** 00124 * Returns a pointer to a clone of the parameters 00125 */ 00126 virtual functor::parameters* clone() const; 00127 00128 /** 00129 * Write the parameters in the given ioHandler 00130 * @param handler the ioHandler to be used 00131 * @param complete if true (the default) the enclosing begin/end will 00132 * be also written, otherwise only the data block will be written. 00133 * @return true if write was successful 00134 */ 00135 virtual bool write(ioHandler& handler,const bool complete=true) const; 00136 00137 /** 00138 * Read the parameters from the given ioHandler 00139 * @param handler the ioHandler to be used 00140 * @param complete if true (the default) the enclosing begin/end will 00141 * be also written, otherwise only the data block will be written. 00142 * @return true if write was successful 00143 */ 00144 virtual bool read(ioHandler& handler,const bool complete=true); 00145 00146 # ifdef _LTI_MSC_6 00147 /** 00148 * This function is required by MSVC only, as a workaround for a 00149 * very awful bug, which exists since MSVC V.4.0, and still by 00150 * V.6.0 with all bugfixes (so called "service packs") remains 00151 * there... This method is also public due to another bug, so please 00152 * NEVER EVER call this method directly: use read() instead 00153 */ 00154 bool readMS(ioHandler& handler,const bool complete=true); 00155 00156 /** 00157 * This function is required by MSVC only, as a workaround for a 00158 * very awful bug, which exists since MSVC V.4.0, and still by 00159 * V.6.0 with all bugfixes (so called "service packs") remains 00160 * there... This method is also public due to another bug, so please 00161 * NEVER EVER call this method directly: use write() instead 00162 */ 00163 bool writeMS(ioHandler& handler,const bool complete=true) const; 00164 # endif 00165 00166 // ------------------------------------------------ 00167 // the parameters 00168 // ------------------------------------------------ 00169 00170 /** 00171 * Method used to interpolate unknown pixel values. 00172 * 00173 * Default value: Simple 00174 */ 00175 eBayerMethod method; 00176 00177 /** 00178 * Pattern used in input data. 00179 * 00180 * Default value: RGGB 00181 */ 00182 eBayerPattern bayerPattern; 00183 00184 }; 00185 00186 /** 00187 * Default constructor 00188 */ 00189 bayerDemosaicing(); 00190 00191 /** 00192 * Construct a functor using the given parameters 00193 */ 00194 bayerDemosaicing(const parameters& par); 00195 00196 /** 00197 * Copy constructor 00198 * @param other the object to be copied 00199 */ 00200 bayerDemosaicing(const bayerDemosaicing& other); 00201 00202 /** 00203 * Destructor 00204 */ 00205 virtual ~bayerDemosaicing(); 00206 00207 /** 00208 * Returns the name of this type ("bayerDemosaicing") 00209 */ 00210 virtual const char* getTypeName() const; 00211 00212 /** 00213 * operates on a copy of the given %parameters. 00214 * @param src matrix<ubyte> with the source data. 00215 * @param dest matrix<ubyte> where the result will be left. 00216 * @return true if apply successful or false otherwise. 00217 */ 00218 bool apply(const matrix<ubyte>& src,matrix<rgbPixel>& dest) const; 00219 00220 00221 /** 00222 * Copy data of "other" functor. 00223 * @param other the functor to be copied 00224 * @return a reference to this functor object 00225 */ 00226 bayerDemosaicing& copy(const bayerDemosaicing& other); 00227 00228 /** 00229 * Alias for copy member 00230 * @param other the functor to be copied 00231 * @return a reference to this functor object 00232 */ 00233 bayerDemosaicing& operator=(const bayerDemosaicing& other); 00234 00235 /** 00236 * Returns a pointer to a clone of this functor. 00237 */ 00238 virtual functor* clone() const; 00239 00240 /** 00241 * Returns used parameters 00242 */ 00243 const parameters& getParameters() const; 00244 00245 protected: 00246 bool simpleDemosaicingRG(const eBayerPattern pattern, 00247 const matrix<ubyte>& src, 00248 matrix<rgbPixel>& dest) const; 00249 00250 bool nearestNeighborDemosaicingRG(const eBayerPattern pattern, 00251 const matrix<ubyte>& src, 00252 matrix<rgbPixel>& dest) const; 00253 bool simpleDemosaicingBG(const eBayerPattern pattern, 00254 const matrix<ubyte>& src, 00255 matrix<rgbPixel>& dest) const; 00256 00257 bool nearestNeighborDemosaicingBG(const eBayerPattern pattern, 00258 const matrix<ubyte>& src, 00259 matrix<rgbPixel>& dest) const; 00260 bool generateGrayImage(const matrix<ubyte>& src, 00261 matrix<rgbPixel>& dest) const; 00262 }; 00263 00264 // global read and write functions for enumerations 00265 /** 00266 * read function for bayerDemosaicing::eBayerMethod 00267 * 00268 * @ingroup gStorable 00269 */ 00270 bool read(ioHandler& handler, bayerDemosaicing::eBayerMethod& data); 00271 00272 /** 00273 * write function for bayerDemosaicing::eBayerMethod 00274 * 00275 * @ingroup gStorable 00276 */ 00277 bool write(ioHandler& handler, const bayerDemosaicing::eBayerMethod& data); 00278 00279 /** 00280 * read function for bayerDemosaicing::eBayerPattern 00281 * 00282 * @ingroup gStorable 00283 */ 00284 bool read(ioHandler& handler, bayerDemosaicing::eBayerPattern& data); 00285 00286 /** 00287 * write function for bayerDemosaicing::eBayerPattern 00288 * 00289 * @ingroup gStorable 00290 */ 00291 bool write(ioHandler& handler, const bayerDemosaicing::eBayerPattern& data); 00292 00293 00294 } 00295 00296 #endif