latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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-Lib: Image Processing and Computer Vision Library 00026 * file .......: ltiViewerFunctor.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 31.12.2002 00030 * revisions ..: $Id: ltiViewerFunctor.h,v 1.7 2006/02/08 12:58:49 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_VIEWER_FUNCTOR_H_ 00034 #define _LTI_VIEWER_FUNCTOR_H_ 00035 00036 #include "ltiTransform.h" 00037 #include "ltiViewer.h" 00038 #include "ltiHistogram.h" 00039 00040 namespace lti { 00041 00042 /** 00043 * This viewerFunctor has as task to prepare an image, that will be 00044 * visualized in the lti::viewer. For this reason, it uses the same 00045 * parameters as the viewer, but it ignores those ones which control 00046 * widget specific stuff like window size and so on. 00047 * 00048 * This way, you can also generate images that you do with your viewer but 00049 * without showing them. 00050 * 00051 * Due to the fact, that viewer alter the "informational" part of the 00052 * parameters, this functor will also do this. This means, after calling 00053 * an apply method, the parameters can contain (if specified to do so) new 00054 * information in the parameters corresponding to the statistics. 00055 */ 00056 class viewerFunctor : public transform { 00057 public: 00058 /** 00059 * the parameters for the class viewerFunctor are the same parameters 00060 * of the lti::viewer 00061 */ 00062 typedef viewer::parameters parameters; 00063 00064 /** 00065 * default constructor 00066 */ 00067 viewerFunctor(); 00068 00069 /** 00070 * Construct a functor using the given parameters 00071 */ 00072 viewerFunctor(const parameters& par); 00073 00074 /** 00075 * copy constructor 00076 * @param other the object to be copied 00077 */ 00078 viewerFunctor(const viewerFunctor& other); 00079 00080 /** 00081 * destructor 00082 */ 00083 virtual ~viewerFunctor(); 00084 00085 /** 00086 * returns the name of this type ("viewerFunctor") 00087 */ 00088 virtual const char* getTypeName() const; 00089 00090 // apply methods! 00091 00092 /** 00093 * create a visualization image for the the input data 00094 * @param src matrix<ubyte> with the source data. 00095 * @param dest matrix<ubyte> where the result will be left. 00096 * @param doStat if true, the statistics for the src will be computed and 00097 * leaved in the informational part of the 00098 * parameters object. 00099 * @return true if apply successful or false otherwise. 00100 */ 00101 bool apply(const matrix<ubyte>& src,image& dest, 00102 const bool doStat=true); 00103 00104 /** 00105 * create a visualization image for the the input data 00106 * @param src matrix<int> with the source data. 00107 * @param dest matrix<int> where the result will be left. 00108 * @param doStat if true, the statistics for the src will be computed and 00109 * leaved in the informational part of the 00110 * parameters object. 00111 * @return true if apply successful or false otherwise. 00112 */ 00113 bool apply(const matrix<int>& src,image& dest, 00114 const bool doStat=true); 00115 00116 /** 00117 * create a visualization image for the the input data 00118 * @param src matrix<float> with the source data. 00119 * @param dest matrix<float> where the result will be left. 00120 * @param doStat if true, the statistics for the src will be computed and 00121 * leaved in the informational part of the 00122 * parameters object. 00123 * @return true if apply successful or false otherwise. 00124 */ 00125 bool apply(const matrix<float>& src,image& dest, 00126 const bool doStat=true); 00127 00128 /** 00129 * create a visualization image for the the input data 00130 * @param src matrix<double> with the source data. 00131 * @param dest matrix<double> where the result will be left. 00132 * @param doStat if true, the statistics for the src will be computed and 00133 * leaved in the informational part of the 00134 * parameters object. 00135 * @return true if apply successful or false otherwise. 00136 */ 00137 bool apply(const matrix<double>& src,image& dest, 00138 const bool doStat=true); 00139 00140 00141 /** 00142 * create a visualization image for the the input data 00143 * @param src image with the source data. 00144 * @param dest image where the result will be left. 00145 * @param doStat if true, the statistics for the src will be computed and 00146 * leaved in the informational part of the 00147 * parameters object. 00148 * @return true if apply successful or false otherwise. 00149 */ 00150 bool apply(const image& src,image& dest, 00151 const bool doStat=true); 00152 00153 /** 00154 * create a visualization image for the the input data 00155 * @param src histogram1D with the source data. 00156 * @param dest image where the result will be left. 00157 * @param doStat if true, the statistics for the src will be computed and 00158 * leaved in the informational part of the 00159 * parameters object. 00160 * @return true if apply successful or false otherwise. 00161 */ 00162 bool apply(const histogram1D& src,image& dest, 00163 const bool doStat=true); 00164 00165 /** 00166 * create a visualization image for the the input data 00167 * @param src histogram1D with the source data. 00168 * @param dest image where the result will be left. 00169 * @param doStat if true, the statistics for the src will be computed and 00170 * leaved in the informational part of the 00171 * parameters object. 00172 * @return true if apply successful or false otherwise. 00173 */ 00174 bool apply(const histogram2D& src,image& dest, 00175 const bool doStat=true); 00176 00177 /** 00178 * create a visualization image for the the input data 00179 * @param src vector<double> with the source data. 00180 * @param dest image where the result will be left. 00181 * @param doStat if true, the statistics for the src will be computed and 00182 * leaved in the informational part of the 00183 * parameters object. 00184 * @return true if apply successful or false otherwise. 00185 */ 00186 bool apply(const dvector& src,image& dest, 00187 const bool doStat=true); 00188 00189 /** 00190 * create a visualization image for the the input data 00191 * @param src vector<float> with the source data. 00192 * @param dest image where the result will be left. 00193 * @param doStat if true, the statistics for the src will be computed and 00194 * leaved in the informational part of the 00195 * parameters object. 00196 * @return true if apply successful or false otherwise. 00197 */ 00198 bool apply(const vector<float>& src,image& dest, 00199 const bool doStat=true); 00200 00201 /** 00202 * create a visualization image for the the input data 00203 * @param src vector<float> with the source data. 00204 * @param dest image where the result will be left. 00205 * @param doStat if true, the statistics for the src will be computed and 00206 * leaved in the informational part of the 00207 * parameters object. 00208 * @return true if apply successful or false otherwise. 00209 */ 00210 bool apply(const vector<int>& src,image& dest, 00211 const bool doStat=true); 00212 00213 /** 00214 * create a visualization image for the the input data 00215 * @param src vector<float> with the source data. 00216 * @param dest image where the result will be left. 00217 * @param doStat if true, the statistics for the src will be computed and 00218 * leaved in the informational part of the 00219 * parameters object. 00220 * @return true if apply successful or false otherwise. 00221 */ 00222 bool apply(const vector<ubyte>& src,image& dest, 00223 const bool doStat=true); 00224 00225 /** 00226 * copy data of "other" functor. 00227 * @param other the functor to be copied 00228 * @return a reference to this functor object 00229 */ 00230 viewerFunctor& copy(const viewerFunctor& other); 00231 00232 /** 00233 * alias for copy member 00234 * @param other the functor to be copied 00235 * @return a reference to this functor object 00236 */ 00237 viewerFunctor& operator=(const viewerFunctor& other); 00238 00239 /** 00240 * returns a pointer to a clone of this functor. 00241 */ 00242 virtual functor* clone() const; 00243 00244 /** 00245 * returns used parameters 00246 */ 00247 const parameters& getParameters() const; 00248 00249 /** 00250 * returns a read/write-reference of the used parameters. 00251 * 00252 * This is required by the viewer, in order to write in the 00253 * parameters the options specified by the user in the Configuration 00254 * Dialogs and to write the statistics (informational data) into the 00255 * parameters object. 00256 */ 00257 parameters& getParameters(); 00258 00259 /** 00260 * compute the values for contrast and brightness necessary to map 00261 * the minI and maxI attributes in the parameters to the 00262 * given minp and maxp values. 00263 * Note that must be minp <= maxp. 00264 */ 00265 void computeContrastBrightness(const float minp, 00266 const float maxp, 00267 const float norm, 00268 float& c, 00269 float& b) const; 00270 protected: 00271 00272 /** 00273 * The input channel is a scalar matrix 00274 */ 00275 bool scalarToImage(const matrix<ubyte>& chnl,image& img,const bool doStat); 00276 00277 /** 00278 * The input channel is a scalar matrix 00279 */ 00280 bool scalarToImage(const matrix<int>& chnl,image& img,const bool doStat); 00281 00282 /** 00283 * The input channel is a scalar matrix 00284 */ 00285 bool scalarToImage(const matrix<float>& chnl,image& img,const bool doStat); 00286 00287 /** 00288 * The input channel is a scalar matrix 00289 */ 00290 bool scalarToImage(const matrix<double>& chnl,image& img, 00291 const bool doStat); 00292 00293 /** 00294 * The input channel is a scalar matrix 00295 */ 00296 bool scalarToImage(const dvector& vct,image& img, 00297 const bool doStat); 00298 00299 /** 00300 * The input channel is a scalar matrix 00301 */ 00302 bool imageToImage(const image& chnl,image& img,const bool doStat); 00303 00304 /** 00305 * The input channel is a label map 00306 */ 00307 bool labelsToImage(const matrix<ubyte>& chnl,image& img,const bool doStat); 00308 00309 /** 00310 * The input channel is a label map 00311 */ 00312 bool labelsToImage(const matrix<int>& chnl,image& img,const bool doStat); 00313 00314 /** 00315 * Zoom the image 00316 */ 00317 bool zoom(image& img); 00318 00319 /** 00320 * statistics 00321 */ 00322 bool statistics(const matrix<ubyte>& chnl,parameters& par) const; 00323 00324 /** 00325 * statistics 00326 */ 00327 bool statistics(const matrix<int>& chnl,parameters& par) const; 00328 00329 /** 00330 * statistics 00331 */ 00332 bool statistics(const matrix<float>& chnl,parameters& par) const; 00333 00334 /** 00335 * statistics 00336 */ 00337 bool statistics(const matrix<double>& chnl,parameters& par) const; 00338 00339 /** 00340 * statistics 00341 */ 00342 bool statistics(const image& img,parameters& par) const; 00343 00344 /** 00345 * statistics 00346 */ 00347 bool statistics(const dvector& img,parameters& par) const; 00348 00349 /** 00350 * compute the static color palettes used to create the images 00351 */ 00352 static void computePalettes(); 00353 00354 /** 00355 * the static color palettes 00356 */ 00357 //@{ 00358 00359 /** 00360 * The gray palette 00361 */ 00362 static palette grayPalette; 00363 00364 /** 00365 * The gray palette 00366 */ 00367 static palette redPalette; 00368 00369 /** 00370 * The gray palette 00371 */ 00372 static palette greenPalette; 00373 00374 /** 00375 * The gray palette 00376 */ 00377 static palette bluePalette; 00378 00379 /** 00380 * The gray palette 00381 */ 00382 static palette huePalette; 00383 //@} 00384 00385 /** 00386 * compute, using the informational data in the parameters, 00387 * the required linear transformation to change the contrast of 00388 * an image intensity. 00389 * @param norm the norm used for the current type (255 or 1) 00390 * @param m slope 00391 * @param b offset 00392 */ 00393 void computeLinearTrans(const float norm,float& m,float& b) const; 00394 00395 /** 00396 * compute, for the contrast argument c and the 00397 * minI and maxI attributes in the parameters object, 00398 * the values to which this two extrema are mapped, if the brightness = 0; 00399 */ 00400 void computeContrastExtrema(const float norm, 00401 const float c, 00402 float& minp,float& maxp)const; 00403 00404 }; 00405 } 00406 00407 #endif