CVB++ 15.0
algorithm.hpp
1#pragma once
2
3#include <exception>
4#include <memory>
5#include <new>
6#include <stdexcept>
7
8#include "_cexports/c_img.h"
9
10#include "global.hpp"
11#include "image.hpp"
12#include "image_plane.hpp"
13
14#include "utilities/system_info.hpp"
15
16namespace Cvb
17{
18
20 CVB_BEGIN_INLINE_NS
22
24
37 inline std::unique_ptr<Image> AffineTransform(const Image &image, AffineMatrix2D affineMatrix, Area2D area)
38 {
39 return Internal::DoBoolCallObjectOut<Image>([&](void *&img) {
40 return CVB_CALL_CAPI(
41 CreateAreaAffineTransformedImage(image.Handle(), *reinterpret_cast<CExports::TCoordinateMap *>(&affineMatrix),
42 *reinterpret_cast<CExports::TArea *>(&area), img));
43 });
44 }
45
47
56 {
57 return AffineTransform(image, affineMatrix,
58 Area2D(static_cast<Rect<double>>(image.Bounds()), AffineMatrix2D::Identity()));
59 }
60
62
73 {
74 return Internal::DoBoolCallObjectOut<Image>([&](void *&img) {
75 return CVB_CALL_CAPI(
76 CreateMatrixTransformedImageEx(image.Handle(), *reinterpret_cast<CExports::TMatrix *>(&matrix), img));
77 });
78 }
79
81
91 {
92 return Internal::DoBoolCallObjectOut<Image>([&](void *&img) {
93 return CVB_CALL_CAPI(MapTo8Bit(
94 image.Handle(),
95 static_cast<CExports::cvbbool_t>(planeNormalization == PlaneNormalization::Identical ? (true) : false), img));
96 });
97 }
98
101
110 inline std::unique_ptr<Image> NormalizeMinMax(const Image &image, double targetMin, double targetMax)
111 {
112 return Internal::DoBoolCallObjectOut<Image>([&](void *&img) {
113 return CVB_CALL_CAPI(
114 CreateNormalizedImage(image.Handle(), CExports::Normalize_MinMax, targetMin, targetMax, img));
115 });
116 }
117
120
129 inline std::unique_ptr<Image> NormalizeMeanVariance(const Image &image, double targetMean, double targetVariance)
130 {
131 return Internal::DoBoolCallObjectOut<Image>([&](void *&img) {
132 return CVB_CALL_CAPI(
133 CreateNormalizedImage(image.Handle(), CExports::Normalize_MeanVariance, targetMean, targetVariance, img));
134 });
135 }
136
139
153 inline std::unique_ptr<Image> PolarTransform(const Image &image, Point2D<double> center, double innerRadius,
154 double outerRadius, Angle startAngle, Angle totalAngle)
155 {
156 return Internal::DoBoolCallObjectOut<Image>([&](void *&img) {
157 return CVB_CALL_CAPI(CreatePolarImageEx(image.Handle(), center.X(), center.Y(), startAngle.Deg(),
158 totalAngle.Deg(), std::min(innerRadius, outerRadius),
159 std::max(innerRadius, outerRadius), img));
160 });
161 }
162
165
177 inline std::unique_ptr<Image> PolarTransform(const Image &image, Point2D<double> center, double innerRadius,
178 double outerRadius)
179 {
180 return PolarTransform(image, center, innerRadius, outerRadius, Angle::FromDegrees(0.0), Angle::FromDegrees(360.0));
181 }
182
184
195 inline std::unique_ptr<Image> InversePolarTransform(const Image &image, Angle startAngle, double innerRadius)
196 {
197 return Internal::DoBoolCallObjectOut<Image>([&](void *&img) {
198 return CVB_CALL_CAPI(CreateInversePolarImage(image.Handle(), startAngle.Deg(), innerRadius, img));
199 });
200 }
201
203
216 inline void InversePolarTransformToDst(const Image &imageSrc, Point2D<double> center, Angle startAngle,
217 double innerRadius, Image &imageDst)
218 {
219 if (CVB_CALL_CAPI(InversePolarTransform(imageSrc.Handle(), center.X(), center.Y(), startAngle.Deg(), innerRadius,
220 imageDst.Handle())))
221 Utilities::SystemInfo::ThrowLastError();
222 imageDst.RaisePixelContentChanged();
223 }
224
225 CVB_END_INLINE_NS
226
227} // namespace Cvb
Compacted affine matrix describing the Common Vision Blox coordinate system.
Definition affine_matrix_2d.hpp:17
static AffineMatrix2D Identity() noexcept
The identity element.
Definition affine_matrix_2d.hpp:24
Object for convenient and type - safe handling of angles.
Definition angle.hpp:16
double Deg() const noexcept
Get the value in degrees.
Definition angle.hpp:89
static Angle FromDegrees(double deg, bool trim=false) noexcept
Create an angle in degrees.
Definition angle.hpp:25
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
std::unique_ptr< Image > PolarTransform(const Image &image, Point2D< double > center, double innerRadius, double outerRadius)
Create a polar transformation (i.e. unwrap a ring structure from inside source image into a rectangul...
Definition algorithm.hpp:177
void RaisePixelContentChanged() const
Inform clients listening to the pixel content changed event, that the image data has been completely ...
Definition decl_image.hpp:448
Image(Size2D< int > size, int numPlanes=1, DataType dataType=DataType::Int8BppUnsigned())
Constructs an uninitialized image with the given parameters.
Definition decl_image.hpp:197
std::unique_ptr< Image > InversePolarTransform(const Image &image, Angle startAngle, double innerRadius)
Definition algorithm.hpp:195
std::unique_ptr< Image > NormalizeMeanVariance(const Image &image, double targetMean, double targetVariance)
Normalize an input image using mean/variance normalization (the gray values of the image will be stre...
Definition algorithm.hpp:129
std::unique_ptr< Image > LinearTransform(const Image &image, Matrix2D matrix)
Creates a linear transformation (matrix transformation).
Definition algorithm.hpp:72
std::unique_ptr< Image > AffineTransform(const Image &image, AffineMatrix2D affineMatrix, Area2D area)
Creates an affine transformation (homogeneous matrix transformation) of an area of the given image.
Definition algorithm.hpp:37
void InversePolarTransformToDst(const Image &imageSrc, Point2D< double > center, Angle startAngle, double innerRadius, Image &imageDst)
Create an inverse polar transformed image (i.e. transform an unwrapped image back into a ring structu...
Definition algorithm.hpp:216
Rect< int > Bounds() const noexcept
Bounding rectangle of the image in pixels.
Definition decl_image.hpp:438
std::unique_ptr< Image > NormalizeMinMax(const Image &image, double targetMin, double targetMax)
Normalize an input image using min/max normalization (the gray values of the image will be stretched ...
Definition algorithm.hpp:110
std::unique_ptr< Image > MapTo8Bit(const Image &image, PlaneNormalization planeNormalization=PlaneNormalization::Identical)
Take an input image and scale the pixel values to fit into the 8 bit value range.
Definition algorithm.hpp:89
std::unique_ptr< Image > PolarTransform(const Image &image, Point2D< double > center, double innerRadius, double outerRadius, Angle startAngle, Angle totalAngle)
Create a polar transformation (i.e. unwrap a ring structure from inside source image into a rectangul...
Definition algorithm.hpp:153
std::unique_ptr< Image > AffineTransform(const Image &image, AffineMatrix2D affineMatrix)
Creates an affine transformation (homogeneous matrix transformation) of the whole image.
Definition algorithm.hpp:55
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
Double precision 2x2 matrix class.
Definition matrix_2d.hpp:16
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
T X() const noexcept
Gets the x-component of the point.
Definition point_2d.hpp:84
T Y() const noexcept
Gets the y-component of the point.
Definition point_2d.hpp:104
Rectangle object.
Definition rect.hpp:24
cvbbool_t CreateMatrixTransformedImageEx(IMG ImageIn, TMatrix Matrix, IMG &ImageOut)
cvbbool_t CreateAreaAffineTransformedImage(IMG ImageIn, const TCoordinateMap &CS, const TArea &Area, IMG &ImageOut)
cvbbool_t CreateNormalizedImage(IMG ImageIn, TNormalizeMode Mode, double TargetMeanMin, double TargetStandardDeviationMax, IMG &ImageOut)
cvbbool_t CreatePolarImageEx(IMG ImageIn, double CenterX, double CenterY, double Alpha0, double AlphaTotal, double InnerRadius, double OuterRadius, IMG &ImageOut)
cvbbool_t CreateInversePolarImage(IMG ImageIn, double Alpha0, double InnerRadius, IMG &ImageOut)
T max(T... args)
T min(T... args)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::unique_ptr< Image > InversePolarTransform(const Image &image, Angle startAngle, double innerRadius)
Definition algorithm.hpp:195
std::unique_ptr< Image > AffineTransform(const Image &image, AffineMatrix2D affineMatrix, Area2D area)
Creates an affine transformation (homogeneous matrix transformation) of an area of the given image.
Definition algorithm.hpp:37
std::unique_ptr< Image > MapTo8Bit(const Image &image, PlaneNormalization planeNormalization=PlaneNormalization::Identical)
Take an input image and scale the pixel values to fit into the 8 bit value range.
Definition algorithm.hpp:89
std::unique_ptr< Image > PolarTransform(const Image &image, Point2D< double > center, double innerRadius, double outerRadius, Angle startAngle, Angle totalAngle)
Create a polar transformation (i.e. unwrap a ring structure from inside source image into a rectangul...
Definition algorithm.hpp:153
PlaneNormalization
Plane handling for normalization.
Definition global.hpp:277
@ Identical
Definition global.hpp:285