latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 1998, 1999, 2000, 2001 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file can be used with the LTI-Computer Vision Library (LTI-Lib) 00006 * (please note this file is NOT part of the LTI-Lib) 00007 * This code is based on the original C code by S. Smith, which contains 00008 * following header: 00009 * 00010 ********************************************************************** 00011 * 00012 * SUSAN Version 2l by Stephen Smith 00013 * 00014 * Oxford Centre for Functional Magnetic Resonance Imaging of the 00015 * Brain, Department of Clinical Neurology, Oxford University, Oxford, 00016 * UK (Previously in Computer Vision and Image Processing Group - now 00017 * Computer Vision and Electro Optics Group - DERA Chertsey, UK) 00018 * 00019 * Email: steve@fmrib.ox.ac.uk 00020 * WWW: http://www.fmrib.ox.ac.uk/~steve 00021 * 00022 * (C) Crown Copyright (1995-1999), Defence Evaluation and Research Agency, 00023 * Farnborough, Hampshire, GU14 6TD, UK 00024 * DERA WWW site: 00025 * http://www.dera.gov.uk/ 00026 * DERA Computer Vision and Electro Optics Group WWW site: 00027 * http://www.dera.gov.uk/imageprocessing/dera/group_home.html 00028 * DERA Computer Vision and Electro Optics Group point of contact: 00029 * Dr. John Savage, jtsavage@dera.gov.uk, +44 1344 633203 00030 * 00031 * A UK patent has been granted: "Method for digitally processing 00032 * images to determine the position of edges and/or corners therein for 00033 * guidance of unmanned vehicle", UK Patent 2272285. Proprietor: 00034 * Secretary of State for Defence, UK. 15 January 1997 00035 * 00036 * This code is issued for research purposes only and remains the 00037 * property of the UK Secretary of State for Defence. This code must 00038 * not be passed on without this header information being kept 00039 * intact. This code must not be sold. 00040 ********************************************************************** 00041 * 00042 * 00043 * 00044 * The LTI-Lib is free software; you can redistribute it and/or 00045 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00046 * as published by the Free Software Foundation; either version 2.1 of 00047 * the License, or (at your option) any later version. 00048 * 00049 * The LTI-Lib is distributed in the hope that it will be 00050 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00051 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00052 * GNU Lesser General Public License for more details. 00053 * 00054 * You should have received a copy of the GNU Lesser General Public 00055 * License along with the LTI-Lib; see the file LICENSE. If 00056 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00057 * Suite 330, Boston, MA 02111-1307, USA. 00058 * 00059 */ 00060 00061 /*---------------------------------------------------------------- 00062 * project ....: LTI Digital Image/Signal Processing Library 00063 * file .......: ltiSusanDenoise.h 00064 * authors ....: Christian Harte 00065 * organization: LTI, RWTH Aachen 00066 * creation ...: 18.4.2000 00067 * revisions ..: ltiSusanDenoise.h,v $ 00068 */ 00069 00070 /** 00071 * \file ltiSusanDenoise.h Susan Denoiser: denoise a channel of a 00072 * picture using the susan denoise algorithm. in most cases only the 00073 * intensity channel needs to be denoised. But if only one channel is 00074 * affected by the noise, that one can be processed on its own. 00075 */ 00076 00077 #include "ltiConfig.h" 00078 00079 #ifndef HAVE_SUSAN 00080 #ifdef _LTI_MSC_VER 00081 #pragma message("Configuration Error:") 00082 #pragma message("Change in src/basics/ltiWinConfig.h HAVE_SUSAN to 1") 00083 #else 00084 #warning "Configuration Error:" 00085 #warning "Change in src/basics/config.h HAVE_SUSAN to 1" 00086 #endif 00087 #endif 00088 00089 #ifndef _LTI_SUSAN_DENOISE_H_ 00090 #define _LTI_SUSAN_DENOISE_H_ 00091 00092 #include "ltiImage.h" 00093 #include "ltiModifier.h" 00094 00095 namespace lti { 00096 /** 00097 * The susan denoiser enhances pictures by removing the noise from 00098 * any colour channel. Most times it gives good results in just 00099 * denoising the intensity channel. It might (in very few cases) be 00100 * better to denoise every channel if the noise strongly differs 00101 * between them. 00102 * 00103 * \code 00104 * lti::susanDenoise denoiser; // the susan denoiser 00105 * lti::susanDenoise::parameters param; 00106 * 00107 * param.kernelSize=9; 00108 * param.threshold=12; 00109 * 00110 * denoiser.setParameters(param); 00111 * 00112 * denoiser.apply(chnl_in,chnl_out); 00113 * \endcode 00114 * 00115 * The parameter kernelSize accepts two values: 9 and 37. It 00116 * specifies the number of pixels around the center to use to 00117 * calculate a value for the new pixel. The large value (37) 00118 * results in very good pictures and the small one (9) makes the 00119 * algorithm about 10 times faster. Giving another value will result 00120 * in kernelSize become 37. 00121 * 00122 * To denoise a single frame the denoiser must be told the maximum 00123 * value of the noise (i.e. +/- 9 gray values). The greater this 00124 * value the more blury the picture becomes. To determine the 00125 * optimal value it is recomended to examine a light area of a 00126 * picture: Adjust the threshold until the noise of this area 00127 * disappears and then don't raise it any more. 00128 * 00129 * There are four ways to call the denoiser: 00130 * 00131 * \code 00132 * denoiser.apply(channel8 chnl,channel8 chnl2); 00133 * denoiser.apply(channel8 chnl2); 00134 * denoiser.apply(channel chnl,channel chnl2); 00135 * denoiser.apply(channel chnl2); 00136 * \endcode 00137 * 00138 * The first call ist the fastest one. If it is possible use this method. 00139 * 00140 */ 00141 class susanDenoise : public modifier { 00142 public: 00143 /** 00144 * the parameters for the class susanDenoise 00145 */ 00146 class parameters : public modifier::parameters { 00147 public: 00148 /** 00149 * default constructor 00150 */ 00151 parameters(); 00152 00153 /** 00154 * copy constructor 00155 */ 00156 parameters(const parameters& other); 00157 00158 /** 00159 * destructor 00160 */ 00161 ~parameters(); 00162 00163 /** 00164 * returns name of this type 00165 */ 00166 const char* getTypeName() const; 00167 00168 /** 00169 * copy member 00170 */ 00171 parameters& copy(const parameters& other); 00172 00173 /** 00174 * returns a pointer to a clone of the parameters 00175 */ 00176 virtual functor::parameters* clone() const; 00177 00178 /** 00179 * write the parameters in the given ioHandler 00180 * @param handler the ioHandler to be used 00181 * @param complete if true (the default) the enclosing begin/end will 00182 * be also written, otherwise only the data block will be written. 00183 * @return true if write was successful 00184 */ 00185 virtual bool write(ioHandler& handler,const bool complete=true) const; 00186 00187 /** 00188 * write the parameters in the given ioHandler 00189 * @param handler the ioHandler to be used 00190 * @param complete if true (the default) the enclosing begin/end will 00191 * be also written, otherwise only the data block will be written. 00192 * @return true if write was successful 00193 */ 00194 virtual bool read(ioHandler& handler,const bool complete=true); 00195 00196 # ifdef _LTI_MSC_6 00197 /** 00198 * this function is required by MSVC only, as a workaround for a 00199 * very awful bug, which exists since MSVC V.4.0, and still by 00200 * V.6.0 with all bugfixes (so called "service packs") remains 00201 * there... This method is public due to another bug, so please 00202 * NEVER EVER call this method directly: use read() instead! 00203 */ 00204 bool readMS(ioHandler& handler,const bool complete=true); 00205 00206 /** 00207 * this function is required by MSVC only, as a workaround for a 00208 * very awful bug, which exists since MSVC V.4.0, and still by 00209 * V.6.0 with all bugfixes (so called "service packs") remains 00210 * there... This method is public due to another bug, so please 00211 * NEVER EVER call this method directly: use write() instead! 00212 */ 00213 bool writeMS(ioHandler& handler,const bool complete=true) const; 00214 # endif 00215 00216 // ------------------------------------------------ 00217 // the parameters 00218 // ------------------------------------------------ 00219 00220 /** 00221 * the kernel size determines the quality of the noise reduction 00222 * and the speed of the algorithm. Use 9 for fast filtering (but not 00223 * a very high quality) or 37 for better quality (about 10 slower). 00224 * The default value is 37 00225 */ 00226 int kernelSize; 00227 00228 /** 00229 * Default value 9 00230 * a value of 9.0 seems to be a good value not to smooth the 00231 * picture to much, but to eliminate all the noise of the 00232 * picture. This value has to be changed if a new image source is 00233 * used. The noisier a picture is the larger this value must be. 00234 */ 00235 double threshold; 00236 }; 00237 00238 /** 00239 * default constructor 00240 */ 00241 susanDenoise(); 00242 00243 /** 00244 * copy constructor 00245 * @param other the object to be copied 00246 */ 00247 susanDenoise(const susanDenoise& other); 00248 00249 /** 00250 * destructor 00251 */ 00252 virtual ~susanDenoise(); 00253 00254 /** 00255 * returns the name of this type ("susanDenoise") 00256 */ 00257 virtual const char* getTypeName() const; 00258 00259 /** 00260 * operates on the given parameter. 00261 * @param srcdest channel8 with the source data. The result 00262 * will be left here too. 00263 * @return true if ok, false otherwise. 00264 */ 00265 bool apply(channel8& srcdest) const; 00266 00267 /** 00268 * operates on the given parameter. 00269 * @param srcdest channel with the source data. The result 00270 * will be left here too. 00271 * @return true if ok, false otherwise. 00272 */ 00273 bool apply(channel& srcdest) const; 00274 00275 /** 00276 * operates on a copy of the given parameters. This ist the 00277 * fastest implementation of the susan denoiser. All other 00278 * apply-functions call this one. It is strongly recommended that 00279 * you use this "apply" for maximum speed! 00280 * 00281 * @param src channel8 with the source data. 00282 * @param dest channel8 where the result will be left. 00283 * @return true if ok, false otherwise. 00284 */ 00285 bool apply(const channel8& src,channel8& dest) const; 00286 00287 /** 00288 * operates on a copy of the given parameters. 00289 * @param src channel with the source data. 00290 * @param dest channel where the result will be left. 00291 * @return true if ok, false otherwise. 00292 */ 00293 bool apply(const channel& src,channel& dest) const; 00294 00295 /** 00296 * copy data of "other" functor. 00297 */ 00298 susanDenoise& copy(const susanDenoise& other); 00299 00300 /** 00301 * returns a pointer to a clone of the functor. 00302 */ 00303 virtual functor* clone() const; 00304 00305 /** 00306 * returns used parameters 00307 */ 00308 const parameters& getParameters() const; 00309 00310 protected: 00311 //try which one produces best results (concerning quality and speed): 00312 typedef int TOTAL_TYPE; 00313 //typedef float TOTAL_TYPE; 00314 00315 /** 00316 * This function is called by susan_smoothing. Don't call it 00317 * yourself. 00318 * @param bp pointer to the brightnes table 00319 * @param thresh brightnis threshold 00320 * @param form form of the evaluation function 00321 */ 00322 static void setupBrightnessLUT(lti::ubyte* bp,int thresh,int form); 00323 00324 /** 00325 * @param threeByThree flag for speed mode: if threeByThree is 1 00326 * the smaller kernel (size 9) ist taken, else this value must be 0. 00327 * @param in pointer to the ubyte array of the input image channel 00328 * @param out pointer to the ubyte array of the output image channel 00329 * @param dt distance threshold - only used if threeByThree is 0. 00330 * It defines the size of the USAN. 00331 * @param xSize x-resolution (columns) of the frame 00332 * @param ySize y-resolution (rows) of the frame 00333 * @param bp pointer to the brightnes table generated by 00334 * setupBrightnessLUT 00335 */ 00336 static void susanSmoothing(int threeByThree, 00337 lti::ubyte* in, 00338 lti::ubyte* &out, 00339 float dt, 00340 int xSize, 00341 int ySize, 00342 lti::ubyte* bp); 00343 /** 00344 * create a border around the image data pointed by "in" using 00345 * tmpImage as temporary buffer. The pointer "in" and the xSize and 00346 * ySize variables will be updated 00347 */ 00348 static int enlarge(lti::ubyte*& in, 00349 lti::ubyte* tmp_image, 00350 int& xSize,int& ySize, 00351 const int& border); 00352 00353 static ubyte median(lti::ubyte* in,int i,int j,int xSize); 00354 00355 00356 00357 }; 00358 } 00359 00360 #endif 00361