CVB++ 15.0
morphology.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# include "../point_2d.hpp"
11# include "../size_2d.hpp"
12
13# include "filter.hpp"
14
15# include <memory>
16
17namespace Cvb
18{
19 CVB_BEGIN_INLINE_NS
20
21 namespace Foundation
22 {
23
25
29 namespace Morphology
30 {
31
33 enum class MorphologyMask
34 {
36 Rectangular = CExports::MM_Rect,
38 Cross = CExports::MM_Cross,
40 Elliptic = CExports::MM_Ellipse
41 };
42
44 enum class DistanceNorm
45 {
47 LInfinity = CExports::DN_LInf,
49 L1 = CExports::DN_L1,
51 L2 = CExports::DN_L2
52 };
53
55
65 inline std::unique_ptr<Image> Erode(const Image &image, MorphologyMask maskType, Size2D<int> maskSize,
66 Point2D<int> maskOffset)
67 {
68 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
69 return CVB_CALL_CAPI(ErodeImage(image.Handle(), static_cast<CExports::TMorphologyMask>(maskType),
70 maskSize.Width(), maskSize.Height(), maskOffset.X(), maskOffset.Y(), nullptr,
71 resimg));
72 });
73 }
74
76
84 inline std::unique_ptr<Image> Erode(const Image &image, MorphologyMask maskType, Size2D<int> maskSize)
85 {
86 return Erode(image, maskType, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
87 }
88
90
103 inline std::unique_ptr<Image> Erode(const Image &image, const Image &mask, Point2D<int> maskOffset)
104 {
105 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
106 return CVB_CALL_CAPI(ErodeImage(image.Handle(), CExports::MM_Custom, mask.Width(), mask.Height(),
107 maskOffset.X(), maskOffset.Y(), mask.Handle(), resimg));
108 });
109 }
110
112
123 inline std::unique_ptr<Image> Erode(const Image &image, const Image &mask)
124 {
125 return Erode(image, mask, Point2D<int>(mask.Width() / 2, mask.Height() / 2));
126 }
127
129
139 inline std::unique_ptr<Image> Dilate(const Image &image, MorphologyMask maskType, Size2D<int> maskSize,
140 Point2D<int> maskOffset)
141 {
142 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
143 return CVB_CALL_CAPI(DilateImage(image.Handle(), static_cast<CExports::TMorphologyMask>(maskType),
144 maskSize.Width(), maskSize.Height(), maskOffset.X(), maskOffset.Y(), nullptr,
145 resimg));
146 });
147 }
148
150
158 inline std::unique_ptr<Image> Dilate(const Image &image, MorphologyMask maskType, Size2D<int> maskSize)
159 {
160 return Dilate(image, maskType, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
161 }
162
164
177 inline std::unique_ptr<Image> Dilate(const Image &image, const Image &mask, Point2D<int> maskOffset)
178 {
179 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
180 return CVB_CALL_CAPI(DilateImage(image.Handle(), CExports::MM_Custom, mask.Width(), mask.Height(),
181 maskOffset.X(), maskOffset.Y(), mask.Handle(), resimg));
182 });
183 }
184
186
197 inline std::unique_ptr<Image> Dilate(const Image &image, const Image &mask)
198 {
199 return Dilate(image, mask, Point2D<int>(mask.Width() / 2, mask.Height() / 2));
200 }
201
203
213 inline std::unique_ptr<Image> Open(const Image &image, MorphologyMask maskType, Size2D<int> maskSize,
214 Point2D<int> maskOffset)
215 {
216 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
217 return CVB_CALL_CAPI(OpeningImage(image.Handle(), static_cast<CExports::TMorphologyMask>(maskType),
218 maskSize.Width(), maskSize.Height(), maskOffset.X(), maskOffset.Y(),
219 nullptr, resimg));
220 });
221 }
222
224
232 inline std::unique_ptr<Image> Open(const Image &image, MorphologyMask maskType, Size2D<int> maskSize)
233 {
234 return Open(image, maskType, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
235 }
236
238
251 inline std::unique_ptr<Image> Open(const Image &image, const Image &mask, Point2D<int> maskOffset)
252 {
253 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
254 return CVB_CALL_CAPI(OpeningImage(image.Handle(), CExports::MM_Custom, mask.Width(), mask.Height(),
255 maskOffset.X(), maskOffset.Y(), mask.Handle(), resimg));
256 });
257 }
258
260
271 inline std::unique_ptr<Image> Open(const Image &image, const Image &mask)
272 {
273 return Open(image, mask, Point2D<int>(mask.Width() / 2, mask.Height() / 2));
274 }
275
277
287 inline std::unique_ptr<Image> Close(const Image &image, MorphologyMask maskType, Size2D<int> maskSize,
288 Point2D<int> maskOffset)
289 {
290 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
291 return CVB_CALL_CAPI(ClosingImage(image.Handle(), static_cast<CExports::TMorphologyMask>(maskType),
292 maskSize.Width(), maskSize.Height(), maskOffset.X(), maskOffset.Y(),
293 nullptr, resimg));
294 });
295 }
296
298
306 inline std::unique_ptr<Image> Close(const Image &image, MorphologyMask maskType, Size2D<int> maskSize)
307 {
308 return Close(image, maskType, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
309 }
310
312
325 inline std::unique_ptr<Image> Close(const Image &image, const Image &mask, Point2D<int> maskOffset)
326 {
327 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
328 return CVB_CALL_CAPI(ClosingImage(image.Handle(), CExports::MM_Custom, mask.Width(), mask.Height(),
329 maskOffset.X(), maskOffset.Y(), mask.Handle(), resimg));
330 });
331 }
332
334
345 inline std::unique_ptr<Image> Close(const Image &image, const Image &mask)
346 {
347 return Close(image, mask, Point2D<int>(mask.Width() / 2, mask.Height() / 2));
348 }
349
352
365 DistanceNorm norm)
366 {
367 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
368 return CVB_CALL_CAPI(DistanceTransformation(plane.Parent().Handle(), plane.Plane(),
369 static_cast<CExports::TFilterMask>(maskSize),
370 static_cast<CExports::TDistanceNorm>(norm), resimg));
371 });
372 }
373
374 } /* namespace Morphology */
375
378
379 using Morphology::Close;
380 using Morphology::Dilate;
382 using Morphology::Erode;
383 using Morphology::Open;
384
385 } /* namespace Foundation */
386 CVB_END_INLINE_NS
387} /* namespace Cvb */
388
389#endif
The Common Vision Blox image.
Definition decl_image.hpp:50
int Width() const noexcept
Width of the image in pixels.
Definition decl_image.hpp:309
int Height() const noexcept
Height of the image in pixels.
Definition decl_image.hpp:299
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
Image plane information container.
Definition decl_image_plane.hpp:29
int Plane() const noexcept
Plane index in the image, to which this plane refers to.
Definition decl_image_plane.hpp:147
const Image & Parent() const noexcept
Image to which this plane descriptor refers to.
Definition detail_image_plane.hpp:87
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
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
T Height() const noexcept
Gets the vertical component of the size.
Definition size_2d.hpp:77
T Width() const noexcept
Gets the horizontal component of the size.
Definition size_2d.hpp:57
cvbres_t ClosingImage(IMG ImgIn, TMorphologyMask MaskType, long MaskWidth, long MaskHeight, long MaskOffsetX, long MaskOffsetY, IMG CustomMask, IMG &ImgOut)
cvbres_t DilateImage(IMG ImgIn, TMorphologyMask MaskType, long MaskWidth, long MaskHeight, long MaskOffsetX, long MaskOffsetY, IMG CustomMask, IMG &ImgOut)
cvbres_t ErodeImage(IMG ImgIn, TMorphologyMask MaskType, long MaskWidth, long MaskHeight, long MaskOffsetX, long MaskOffsetY, IMG CustomMask, IMG &ImgOut)
cvbres_t OpeningImage(IMG ImgIn, TMorphologyMask MaskType, long MaskWidth, long MaskHeight, long MaskOffsetX, long MaskOffsetY, IMG CustomMask, IMG &ImgOut)
cvbres_t DistanceTransformation(IMG ImgIn, long Index, TFilterMask MaskSize, TDistanceNorm Norm, IMG &ImgOut)
FixedFilterSize
Filter size values for filters using a fixed or discrete sized kernel.
Definition filter.hpp:43
Namespace for morphological filter operations available from the Common Vision Blox Foundation packag...
Definition morphology.hpp:30
std::unique_ptr< Image > Close(const Image &image, MorphologyMask maskType, Size2D< int > maskSize, Point2D< int > maskOffset)
Perform a close operation with a selectable filter mask.
Definition morphology.hpp:287
std::unique_ptr< Image > DistanceTransform(const ImagePlane &plane, Filter::FixedFilterSize maskSize, DistanceNorm norm)
This function calculates (and writes into the output image) the distance to the closest pixel in the ...
Definition morphology.hpp:364
std::unique_ptr< Image > Dilate(const Image &image, MorphologyMask maskType, Size2D< int > maskSize, Point2D< int > maskOffset)
Perform a dilation operation with a selectable filter mask.
Definition morphology.hpp:139
MorphologyMask
Available morphology masks.
Definition morphology.hpp:34
@ Rectangular
Rectangular morphology mask.
Definition morphology.hpp:36
@ Elliptic
Elliptic morphology mask.
Definition morphology.hpp:40
@ Cross
Cross-shaped morphology mask.
Definition morphology.hpp:38
std::unique_ptr< Image > Erode(const Image &image, MorphologyMask maskType, Size2D< int > maskSize, Point2D< int > maskOffset)
Perform an erosion operation with a selectable filter mask.
Definition morphology.hpp:65
std::unique_ptr< Image > Open(const Image &image, MorphologyMask maskType, Size2D< int > maskSize, Point2D< int > maskOffset)
Perform an open operation with a selectable filter mask.
Definition morphology.hpp:213
DistanceNorm
Norm for calculating distances.
Definition morphology.hpp:45
@ LInfinity
Infinity norm (a.k.a maximum norm).
Definition morphology.hpp:47
@ L2
L2 norm (a.k.a. euclidean norm).
Definition morphology.hpp:51
@ L1
L1 norm (a.k.a. absolute norm).
Definition morphology.hpp:49
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