Basic Image AlgorithmS Library 2.8.0

ImageCalc.hh

00001 /*
00002 This file is part of the BIAS library (Basic ImageAlgorithmS).
00003 
00004 Copyright (C) 2003-2009    (see file CONTACT for details)
00005   Multimediale Systeme der Informationsverarbeitung
00006   Institut fuer Informatik
00007   Christian-Albrechts-Universitaet Kiel
00008 
00009 
00010 BIAS is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU Lesser General Public License as published by
00012 the Free Software Foundation; either version 2.1 of the License, or
00013 (at your option) any later version.
00014 
00015 BIAS is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU Lesser General Public License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public License
00021 along with BIAS; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 #ifndef __IMAGE_CALC_HH__
00026 #define __IMAGE_CALC_HH__
00027 
00028 #include <Utils/Param.hh>
00029 #include <Base/Image/ImageBase.hh>
00030 #include <Base/Image/ImageIO.hh>
00031 
00032 namespace BIAS
00033 {
00034   /**
00035    * @class ImageCalc
00036    *
00037    * @brief Performs pixelwise arithmetic and boolean operations on images.
00038    *
00039    * @note Over- and underflows are not prevented. You may want to convert
00040    *       your 1-byte images (like char or unsigned char) to float.
00041    * @note The output image is always initialised.
00042    *
00043    * Possible improvements:
00044    * - avoid over- and underflows by clipping to maximum or minimum value
00045    * - generalise for n input images
00046    *
00047    *  @ingroup g_image_other
00048    *  @author Robert Wulff
00049    *  @date 03/2010
00050    */
00051   template<class StorageType>
00052   class BIASImageUtilsBase_EXPORT ImageCalc
00053   {
00054 
00055   public:
00056 
00057     ////////////////////////////////////////////////////////////////////////////
00058     // calculations between two images                                        //
00059     ////////////////////////////////////////////////////////////////////////////
00060 
00061     /**
00062      * @brief Computes the pixelwise sum of the input images.
00063      */
00064     static void Add(const Image<StorageType> &in1,
00065                     const Image<StorageType> &in2,
00066                     Image<StorageType> &out);
00067 
00068     /**
00069      * @brief Computes the pixelwise difference of the input images. The second
00070      *        image is subtracted from the first one.
00071      */
00072     static void Subtract(const Image<StorageType> &in1,
00073                          const Image<StorageType> &in2,
00074                          Image<StorageType> &out);
00075 
00076     /**
00077      * @brief Computes the pixelwise product of the input images.
00078      */
00079     static void Multiply(const Image<StorageType> &in1,
00080                          const Image<StorageType> &in2,
00081                          Image<StorageType> &out);
00082 
00083     /**
00084      * @brief Computes the pixelwise quotient of the input images. The first
00085      *        image is divided by the second one.
00086      *
00087      * @note In case of division by zero the output image's pixel will be set
00088      *       to 0 and a BIASWARN will be printed to stdout
00089      */
00090     static void Divide(const Image<StorageType> &in1,
00091                        const Image<StorageType> &in2,
00092                        Image<StorageType> &out);
00093 
00094     /**
00095      * @brief Performs a pixelwise AND on the input images.
00096      *
00097      * The input images are interpreted binary: input pixel values == 0 are
00098      * treated as FALSE and all values != 0 are interpreted as TRUE. Output
00099      * image will be of same storage type as input images, but will contain only
00100      * binary values, i.e. only 0 and 1.
00101      *
00102      * Each image channel is treated individually.
00103      */
00104     static void And(const Image<StorageType> &in1,
00105                     const Image<StorageType> &in2,
00106                     Image<StorageType> &out);
00107 
00108     /**
00109      * @brief Performs a pixelwise NAND on the input images.
00110      *
00111      * The input images are interpreted binary: input pixel values == 0 are
00112      * treated as FALSE and all values != 0 are interpreted as TRUE. Output
00113      * image will be of same storage type as input images, but will contain only
00114      * binary values, i.e. only 0 and 1.
00115      *
00116      * Each image channel is treated individually.
00117      */
00118     static void Nand(const Image<StorageType> &in1,
00119                      const Image<StorageType> &in2,
00120                      Image<StorageType> &out);
00121 
00122     /**
00123      * @brief Performs a pixelwise OR on the input images.
00124      *
00125      * The input images are interpreted binary: input pixel values == 0 are
00126      * treated as FALSE and all values != 0 are interpreted as TRUE. Output
00127      * image will be of same storage type as input images, but will contain only
00128      * binary values, i.e. only 0 and 1.
00129      *
00130      * Each image channel is treated individually.
00131      */
00132     static void Or(const Image<StorageType> &in1,
00133                    const Image<StorageType> &in2,
00134                    Image<StorageType> &out);
00135 
00136     /**
00137      * @brief Performs a pixelwise NOR on the input images.
00138      *
00139      * The input images are interpreted binary: input pixel values == 0 are
00140      * treated as FALSE and all values != 0 are interpreted as TRUE. Output
00141      * image will be of same storage type as input images, but will contain only
00142      * binary values, i.e. only 0 and 1.
00143      *
00144      * Each image channel is treated individually.
00145      */
00146     static void Nor(const Image<StorageType> &in1,
00147                     const Image<StorageType> &in2,
00148                     Image<StorageType> &out);
00149 
00150     /**
00151      * @brief Performs a pixelwise XOR on the input images.
00152      *
00153      * The input images are interpreted binary: input pixel values == 0 are
00154      * treated as FALSE and all values != 0 are interpreted as TRUE. Output
00155      * image will be of same storage type as input images, but will contain only
00156      * binary values, i.e. only 0 and 1.
00157      *
00158      * Each image channel is treated individually.
00159      */
00160     static void Xor(const Image<StorageType> &in1,
00161                     const Image<StorageType> &in2,
00162                     Image<StorageType> &out);
00163 
00164     ////////////////////////////////////////////////////////////////////////////
00165     // calculations between one image and a scalar                            //
00166     ////////////////////////////////////////////////////////////////////////////
00167 
00168     /**
00169      * @brief Adds the scalar value to each pixel of the input image.
00170      */
00171     static void AddScalar(const Image<StorageType> &in, StorageType scalar,
00172                           Image<StorageType> &out);
00173 
00174     /**
00175      * @brief Subtracts the scalar value from each pixel of the input image.
00176      */
00177     static void SubtractScalar(const Image<StorageType> &in, StorageType scalar,
00178                                Image<StorageType> &out);
00179 
00180     /**
00181      * @brief Multiplies the scalar value to each pixel of the input image.
00182      */
00183     static void MultiplyScalar(const Image<StorageType> &in, StorageType scalar,
00184                                Image<StorageType> &out);
00185 
00186     /**
00187      * @brief Divides each pixel from the input image by the scalar.
00188      *
00189      * @note The scalar must not be 0!
00190      */
00191     static void DivideScalar(const Image<StorageType> &in, StorageType scalar,
00192                              Image<StorageType> &out);
00193 
00194     ////////////////////////////////////////////////////////////////////////////
00195     // calculations on a single image                                         //
00196     ////////////////////////////////////////////////////////////////////////////
00197 
00198     /**
00199      * @brief Computes the natural logarithm (base e) for each pixel.
00200      *
00201      * @note Each pixel's value will be cast to double for the computation and
00202      *       then back to it's original storage type.
00203      */
00204     static void Log(const Image<StorageType> &in, Image<StorageType> &out);
00205 
00206     /**
00207      * @brief Computes the common logarithm (base 10) for each pixel.
00208      *
00209      * @note Each pixel's value will be cast to double for the computation and
00210      *       then back to it's original storage type.
00211      */
00212     static void Log10(const Image<StorageType> &in, Image<StorageType> &out);
00213 
00214     /**
00215      * @brief Computes the absolute value for each pixel.
00216      *
00217      * Obiously only makes sense for signed storage types...
00218      */
00219     static void Abs(const Image<StorageType> &in, Image<StorageType> &out);
00220   };
00221 }
00222 
00223 #endif // __IMAGE_CALC_HH__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends