Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageCalc.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __IMAGE_CALC_HH__
26 #define __IMAGE_CALC_HH__
27 
28 #include <Utils/Param.hh>
29 #include <Base/Image/ImageBase.hh>
30 #include <Base/Image/ImageIO.hh>
31 
32 namespace BIAS
33 {
34  /**
35  * @class ImageCalc
36  *
37  * @brief Performs pixelwise arithmetic and boolean operations on images.
38  *
39  * @note Over- and underflows are not prevented. You may want to convert
40  * your 1-byte images (like char or unsigned char) to float.
41  * @note The output image is always initialised.
42  *
43  * Possible improvements:
44  * - avoid over- and underflows by clipping to maximum or minimum value
45  * - generalise for n input images
46  *
47  * @ingroup g_image_other
48  * @author Robert Wulff
49  * @date 03/2010
50  */
51  template<class StorageType>
52  class BIASImageUtilsBase_EXPORT ImageCalc
53  {
54 
55  public:
56 
57  ////////////////////////////////////////////////////////////////////////////
58  // calculations between two images //
59  ////////////////////////////////////////////////////////////////////////////
60 
61  /**
62  * @brief Computes the pixelwise sum of the input images.
63  */
64  static void Add(const Image<StorageType> &in1,
65  const Image<StorageType> &in2,
66  Image<StorageType> &out);
67 
68  /**
69  * @brief Computes the pixelwise difference of the input images. The second
70  * image is subtracted from the first one.
71  */
72  static void Subtract(const Image<StorageType> &in1,
73  const Image<StorageType> &in2,
74  Image<StorageType> &out);
75 
76  /**
77  * @brief Computes the pixelwise product of the input images.
78  */
79  static void Multiply(const Image<StorageType> &in1,
80  const Image<StorageType> &in2,
81  Image<StorageType> &out);
82 
83  /**
84  * @brief Computes the pixelwise quotient of the input images. The first
85  * image is divided by the second one.
86  *
87  * @note In case of division by zero the output image's pixel will be set
88  * to 0 and a BIASWARN will be printed to stdout
89  */
90  static void Divide(const Image<StorageType> &in1,
91  const Image<StorageType> &in2,
92  Image<StorageType> &out);
93 
94  /**
95  * @brief Performs a pixelwise AND on the input images.
96  *
97  * The input images are interpreted binary: input pixel values == 0 are
98  * treated as FALSE and all values != 0 are interpreted as TRUE. Output
99  * image will be of same storage type as input images, but will contain only
100  * binary values, i.e. only 0 and 1.
101  *
102  * Each image channel is treated individually.
103  */
104  static void And(const Image<StorageType> &in1,
105  const Image<StorageType> &in2,
106  Image<StorageType> &out);
107 
108  /**
109  * @brief Performs a pixelwise NAND on the input images.
110  *
111  * The input images are interpreted binary: input pixel values == 0 are
112  * treated as FALSE and all values != 0 are interpreted as TRUE. Output
113  * image will be of same storage type as input images, but will contain only
114  * binary values, i.e. only 0 and 1.
115  *
116  * Each image channel is treated individually.
117  */
118  static void Nand(const Image<StorageType> &in1,
119  const Image<StorageType> &in2,
120  Image<StorageType> &out);
121 
122  /**
123  * @brief Performs a pixelwise OR on the input images.
124  *
125  * The input images are interpreted binary: input pixel values == 0 are
126  * treated as FALSE and all values != 0 are interpreted as TRUE. Output
127  * image will be of same storage type as input images, but will contain only
128  * binary values, i.e. only 0 and 1.
129  *
130  * Each image channel is treated individually.
131  */
132  static void Or(const Image<StorageType> &in1,
133  const Image<StorageType> &in2,
134  Image<StorageType> &out);
135 
136  /**
137  * @brief Performs a pixelwise NOR on the input images.
138  *
139  * The input images are interpreted binary: input pixel values == 0 are
140  * treated as FALSE and all values != 0 are interpreted as TRUE. Output
141  * image will be of same storage type as input images, but will contain only
142  * binary values, i.e. only 0 and 1.
143  *
144  * Each image channel is treated individually.
145  */
146  static void Nor(const Image<StorageType> &in1,
147  const Image<StorageType> &in2,
148  Image<StorageType> &out);
149 
150  /**
151  * @brief Performs a pixelwise XOR on the input images.
152  *
153  * The input images are interpreted binary: input pixel values == 0 are
154  * treated as FALSE and all values != 0 are interpreted as TRUE. Output
155  * image will be of same storage type as input images, but will contain only
156  * binary values, i.e. only 0 and 1.
157  *
158  * Each image channel is treated individually.
159  */
160  static void Xor(const Image<StorageType> &in1,
161  const Image<StorageType> &in2,
162  Image<StorageType> &out);
163 
164  ////////////////////////////////////////////////////////////////////////////
165  // calculations between one image and a scalar //
166  ////////////////////////////////////////////////////////////////////////////
167 
168  /**
169  * @brief Adds the scalar value to each pixel of the input image.
170  */
171  static void AddScalar(const Image<StorageType> &in, StorageType scalar,
172  Image<StorageType> &out);
173 
174  /**
175  * @brief Subtracts the scalar value from each pixel of the input image.
176  */
177  static void SubtractScalar(const Image<StorageType> &in, StorageType scalar,
178  Image<StorageType> &out);
179 
180  /**
181  * @brief Multiplies the scalar value to each pixel of the input image.
182  */
183  static void MultiplyScalar(const Image<StorageType> &in, StorageType scalar,
184  Image<StorageType> &out);
185 
186  /**
187  * @brief Divides each pixel from the input image by the scalar.
188  *
189  * @note The scalar must not be 0!
190  */
191  static void DivideScalar(const Image<StorageType> &in, StorageType scalar,
192  Image<StorageType> &out);
193 
194  ////////////////////////////////////////////////////////////////////////////
195  // calculations on a single image //
196  ////////////////////////////////////////////////////////////////////////////
197 
198  /**
199  * @brief Computes the natural logarithm (base e) for each pixel.
200  *
201  * @note Each pixel's value will be cast to double for the computation and
202  * then back to it's original storage type.
203  */
204  static void Log(const Image<StorageType> &in, Image<StorageType> &out);
205 
206  /**
207  * @brief Computes the common logarithm (base 10) for each pixel.
208  *
209  * @note Each pixel's value will be cast to double for the computation and
210  * then back to it's original storage type.
211  */
212  static void Log10(const Image<StorageType> &in, Image<StorageType> &out);
213 
214  /**
215  * @brief Computes the absolute value for each pixel.
216  *
217  * Obiously only makes sense for signed storage types...
218  */
219  static void Abs(const Image<StorageType> &in, Image<StorageType> &out);
220  };
221 }
222 
223 #endif // __IMAGE_CALC_HH__
Performs pixelwise arithmetic and boolean operations on images.
Definition: ImageCalc.hh:52
The image template class for specific storage types.
Definition: Image.hh:78