CVB++ 15.0
arithmetic.hpp
1#pragma once
2
3#if defined _WIN32
4
5# include "../_cexports/c_foundation.h"
6
7# include "../global.hpp"
8# include "../image.hpp"
9# include "../exception.hpp"
10
11# include <vector>
12# include <memory>
13
14namespace Cvb
15{
16 CVB_BEGIN_INLINE_NS
17
18 namespace Foundation
19 {
20
22
26 namespace Arithmetic
27 {
28
30 enum class PixelOverflow
31 {
36 };
37
40 {
45 };
46
48
61 inline std::unique_ptr<Image> Add(const Image &image1, const Image &image2, PixelOverflow overflow)
62 {
63 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
64 return CVB_CALL_CAPI(AddImages(image1.Handle(), image2.Handle(), overflow == PixelOverflow::Scale, resimg));
65 });
66 }
67
69
80 template <class RANGE>
81 inline typename TypedRange<std::unique_ptr<Image>, double, RANGE>::type
82 Add(const Image &image, const RANGE &values, PixelOverflow overflow)
83 {
84 auto valuesRange = MakeRangeAdapter<double>(values, image.PlanesCount());
85
86 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
87 /* Note: need to cast-away const of "values" parameter to match the C-API, the function does not modify it. */
88 return CVB_CALL_CAPI(AddConstant(image.Handle(), const_cast<double *>(valuesRange.Data()),
89 overflow == PixelOverflow::Scale, resimg));
90 });
91 }
92
94
105 inline std::unique_ptr<Image> Add(const Image &image, double value, PixelOverflow overflow)
106 {
107 return Add(image, std::vector<double>(image.PlanesCount(), value), overflow);
108 }
109
111
124 inline std::unique_ptr<Image> Multiply(const Image &image1, const Image &image2, PixelOverflow overflow)
125 {
126 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
127 return CVB_CALL_CAPI(
128 MultiplyImages(image1.Handle(), image2.Handle(), overflow == PixelOverflow::Scale, resimg));
129 });
130 }
131
133
144 template <class RANGE>
145 inline typename TypedRange<std::unique_ptr<Image>, double, RANGE>::type
146 Multiply(const Image &image, const RANGE &values, PixelOverflow overflow)
147 {
148 auto valuesRange = MakeRangeAdapter<double>(values, image.PlanesCount());
149
150 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
151 /* Note: need to cast-away const of "values" parameter to match the C-API, the function does not modify it. */
152 return CVB_CALL_CAPI(MultiplyConstant(image.Handle(), const_cast<double *>(valuesRange.Data()),
153 overflow == PixelOverflow::Scale, resimg));
154 });
155 }
156
158
169 inline std::unique_ptr<Image> Multiply(const Image &image, double value, PixelOverflow overflow)
170 {
171 return Multiply(image, std::vector<double>(image.PlanesCount(), value), overflow);
172 }
173
175
186 inline std::unique_ptr<Image> Subtract(const Image &image1, const Image &image2)
187 {
188 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
189 /* Beware: in the C interface the order of input image arguments is swapped! */
190 return CVB_CALL_CAPI(SubtractImages(image2.Handle(), image1.Handle(), resimg));
191 });
192 }
193
195
204 template <class RANGE>
205 inline typename TypedRange<std::unique_ptr<Image>, double, RANGE>::type Subtract(const Image &image,
206 const RANGE &values)
207 {
208 auto valuesRange = MakeRangeAdapter<double>(values, image.PlanesCount());
209
210 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
211 /* Note: need to cast-away const of "values" parameter to match the C-API, the function does not modify it. */
212 return CVB_CALL_CAPI(SubtractConstant(image.Handle(), const_cast<double *>(valuesRange.Data()), resimg));
213 });
214 }
215
217
226 inline std::unique_ptr<Image> Subtract(const Image &image, double value)
227 {
228 return Subtract(image, std::vector<double>(image.PlanesCount(), value));
229 }
230
233
244 inline std::unique_ptr<Image> Divide(const Image &image1, const Image &image2, int upShift)
245 {
246 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
247 /* Beware: in the C interface the order of input image arguments is swapped! */
248 return CVB_CALL_CAPI(DivideImages(image2.Handle(), image1.Handle(), upShift, resimg));
249 });
250 }
251
253
260 template <class RANGE>
261 inline typename TypedRange<std::unique_ptr<Image>, double, RANGE>::type Divide(const Image &image,
262 const RANGE &values)
263 {
264 auto valuesRange = MakeRangeAdapter<double>(values, image.PlanesCount());
265
266 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
267 /* Note: need to cast-away const of "values" parameter to match the C-API, the function does not modify it. */
268 return CVB_CALL_CAPI(DivideConstant(image.Handle(), const_cast<double *>(valuesRange.Data()), resimg));
269 });
270 }
271
273
280 inline std::unique_ptr<Image> Divide(const Image &image, double value)
281 {
282 return Divide(image, std::vector<double>(image.PlanesCount(), value));
283 }
284
286
296 {
297 return Internal::DoResCallObjectOut<Image>(
298 [&](void *&resimg) { return CVB_CALL_CAPI(AbsoluteImage(image.Handle(), resimg)); });
299 }
300
302
313 inline std::unique_ptr<Image> SubtractAbs(const Image &image1, const Image &image2)
314 {
315 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
316 /* Beware: in the C interface the order of input image arguments is swapped!
317 * (with "absolute" the order actually does not matter, but let's be consistent with Subtract). */
318 return CVB_CALL_CAPI(SubtractImagesAbsolute(image2.Handle(), image1.Handle(), resimg));
319 });
320 }
321
323
332 template <class RANGE>
333 inline typename TypedRange<std::unique_ptr<Image>, double, RANGE>::type SubtractAbs(const Image &image,
334 const RANGE &values)
335 {
336 auto valuesRange = MakeRangeAdapter<double>(values, image.PlanesCount());
337
338 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
339 /* Note: need to cast-away const of "values" parameter to match the C-API, the function does not modify it. */
340 return CVB_CALL_CAPI(
341 SubtractConstantAbsolute(image.Handle(), const_cast<double *>(valuesRange.Data()), resimg));
342 });
343 }
344
346
355 inline std::unique_ptr<Image> SubtractAbs(const Image &image, double value)
356 {
357 return SubtractAbs(image, std::vector<double>(image.PlanesCount(), value));
358 }
359
361
373 inline std::unique_ptr<Image> Square(const Image &image, PixelOverflow overflow)
374 {
375 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
376 return CVB_CALL_CAPI(SquareImage(image.Handle(), overflow == PixelOverflow::Scale, resimg));
377 });
378 }
379
382
394 inline std::unique_ptr<Image> Sqrt(const Image &image, SqrtPixelScaling scaling)
395 {
396 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
397 return CVB_CALL_CAPI(SquareRootImage(image.Handle(), scaling == SqrtPixelScaling::Yes, resimg));
398 });
399 }
400
401 } /* namespace Arithmetic */
402
405
407 using Arithmetic::Add;
408 using Arithmetic::Divide;
410 using Arithmetic::Sqrt;
411 using Arithmetic::Square;
414
415 } /* namespace Foundation */
416 CVB_END_INLINE_NS
417} /* namespace Cvb */
418
419#endif
The Common Vision Blox image.
Definition decl_image.hpp:50
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition decl_image.hpp:247
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
cvbres_t DivideConstant(IMG ImgIn, double Values[], IMG &ImgOut)
cvbres_t MultiplyImages(IMG ImgIn1, IMG ImgIn2, cvbbool_t ScaleResults, IMG &ImgOut)
cvbres_t SquareImage(IMG ImgIn, cvbbool_t ScaleResults, IMG &ImgOut)
cvbres_t SubtractConstant(IMG ImgIn, double Values[], IMG &ImgOut)
cvbres_t AddImages(IMG ImgIn1, IMG ImgIn2, cvbbool_t ScaleResults, IMG &ImgOut)
cvbres_t MultiplyConstant(IMG ImgIn, double Values[], cvbbool_t ScaleResults, IMG &ImgOut)
cvbres_t SubtractConstantAbsolute(IMG ImgIn, double Values[], IMG &ImgOut)
cvbres_t DivideImages(IMG ImgIn1, IMG ImgIn2, long UpShift, IMG &ImgOut)
cvbres_t AddConstant(IMG ImgIn, double Values[], cvbbool_t ScaleResults, IMG &ImgOut)
cvbres_t SquareRootImage(IMG ImgIn, cvbbool_t ScaleResults, IMG &ImgOut)
cvbres_t SubtractImages(IMG ImgIn1, IMG ImgIn2, IMG &ImgOut)
cvbres_t AbsoluteImage(IMG ImgIn, IMG &ImgOut)
cvbres_t SubtractImagesAbsolute(IMG ImgIn1, IMG ImgIn2, IMG &ImgOut)
Namespace for collection of arithmetic functions from the Foundation package.
Definition arithmetic.hpp:27
PixelOverflow
Defines how arithmetic overflows and underflows are handled.
Definition arithmetic.hpp:31
@ Scale
Resulting pixel values are scaled according to the data type's range.
Definition arithmetic.hpp:33
@ Truncate
Resulting pixel values are truncated at the data type's min and max values.
Definition arithmetic.hpp:35
std::unique_ptr< Image > Multiply(const Image &image1, const Image &image2, PixelOverflow overflow)
Multiply the pixel values of both input images to obtain the output image.
Definition arithmetic.hpp:124
std::unique_ptr< Image > Absolute(const Image &image)
Determines the absolute values of the pixels in the input image.
Definition arithmetic.hpp:295
std::unique_ptr< Image > Subtract(const Image &image1, const Image &image2)
Subtract the pixel values of image 2 from image 1 to obtain the output image.
Definition arithmetic.hpp:186
std::unique_ptr< Image > Square(const Image &image, PixelOverflow overflow)
Squares the pixel values of the input image to obtain the output image.
Definition arithmetic.hpp:373
SqrtPixelScaling
Defines the post processing of the Sqrt function.
Definition arithmetic.hpp:40
@ AsIs
Square root result is stored as is (no scaling).
Definition arithmetic.hpp:42
@ Yes
Square root result is scaled to the DataType's range.
Definition arithmetic.hpp:44
std::unique_ptr< Image > SubtractAbs(const Image &image1, const Image &image2)
Subtract the pixel values of image 2 from image 1 to obtain the output image.
Definition arithmetic.hpp:313
std::unique_ptr< Image > Divide(const Image &image1, const Image &image2, int upShift)
Divide the pixel values of image1 by the pixel values of image 2 to obtain the output image and shift...
Definition arithmetic.hpp:244
std::unique_ptr< Image > Sqrt(const Image &image, SqrtPixelScaling scaling)
Calculates the square roots of pixel values of a source image and writes them into the destination im...
Definition arithmetic.hpp:394
std::unique_ptr< Image > Add(const Image &image1, const Image &image2, PixelOverflow overflow)
Add the pixel values of both input images to obtain the output image.
Definition arithmetic.hpp:61
Namespace for the Foundation package.
Definition decl_metric_aqs12_calibration_piece.hpp:11
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
@ Absolute
Scaled rangemap values represent absolute pixel position on sensor.
Definition core_3d.hpp:252