CVB++ 15.0
Loading...
Searching...
No Matches
filter.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 <memory>
14
15namespace Cvb
16{
17 CVB_BEGIN_INLINE_NS
18
19 namespace Foundation
20 {
21
23
27 namespace Filter
28 {
29
31
37 enum class FixedFilterSize
38 {
40 Kernel3x3 = CExports::FM_3x3,
42 Kernel5x5 = CExports::FM_5x5,
44 Kernel7x7 = CExports::FM_7x7
45 };
46
55
57 enum class EdgeFilter
58 {
60 Scharr = CExports::CE_Scharr,
62 Sobel = CExports::CE_Sobel,
64 Sobel2nd = CExports::CE_Sobel2nd
65 };
66
69 {
74 };
75
77
94 inline std::unique_ptr<Image> Canny(const ImagePlane &imagePlane, Filter::EdgeFilter edgeFilter,
95 int lowerThreshold, int upperThreshold)
96 {
97 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
98 return CVB_CALL_CAPI(FilterCanny(imagePlane.Parent().Handle(), imagePlane.Plane(),
99 static_cast<CExports::TCannyEdgeFilter>(edgeFilter), lowerThreshold,
100 upperThreshold, resimg));
101 });
102 }
103
105
113 {
114 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
115 return CVB_CALL_CAPI(FilterLaplace(image.Handle(), static_cast<CExports::TFilterMask>(size), resimg));
116 });
117 }
118
120
127 {
128 return Internal::DoResCallObjectOut<Image>(
129 [&](void *&resimg) { return CVB_CALL_CAPI(FilterSharpening(image.Handle(), resimg)); });
130 }
131
133
141 {
142 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
143 return CVB_CALL_CAPI(FilterLoPass(image.Handle(), static_cast<CExports::TFilterMask>(size), resimg));
144 });
145 }
146
148
156 {
157 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
158 return CVB_CALL_CAPI(FilterHiPass(image.Handle(), static_cast<CExports::TFilterMask>(size), resimg));
159 });
160 }
161
163
171 {
172 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
173 return CVB_CALL_CAPI(FilterGauss(image.Handle(), static_cast<CExports::TFilterMask>(size), resimg));
174 });
175 }
176
179
188 inline std::unique_ptr<Image> BoxMean(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset)
189 {
190 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
191 return CVB_CALL_CAPI(FilterBoxMean(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
192 maskOffset.Y(), resimg));
193 });
194 }
195
198
207 inline std::unique_ptr<Image> BoxMean(const Image &image, Size2D<int> maskSize)
208 {
209 return BoxMean(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
210 }
211
214
223 inline std::unique_ptr<Image> BoxMin(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset)
224 {
225 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
226 return CVB_CALL_CAPI(FilterBoxMin(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
227 maskOffset.Y(), resimg));
228 });
229 }
230
233
242 inline std::unique_ptr<Image> BoxMin(const Image &image, Size2D<int> maskSize)
243 {
244 return BoxMin(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
245 }
246
249
258 inline std::unique_ptr<Image> BoxMax(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset)
259 {
260 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
261 return CVB_CALL_CAPI(FilterBoxMax(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
262 maskOffset.Y(), resimg));
263 });
264 }
265
268
277 inline std::unique_ptr<Image> BoxMax(const Image &image, Size2D<int> maskSize)
278 {
279 return BoxMax(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
280 }
281
284
293 inline std::unique_ptr<Image> BoxMedian(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset)
294 {
295 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
296 return CVB_CALL_CAPI(FilterBoxMedian(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
297 maskOffset.Y(), resimg));
298 });
299 }
300
303
312 inline std::unique_ptr<Image> BoxMedian(const Image &image, Size2D<int> maskSize)
313 {
314 return BoxMedian(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
315 }
316
318
328 {
329 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
330 return CVB_CALL_CAPI(FilterMedianColor(image.Handle(), static_cast<CExports::TFilterMask>(maskType), resimg));
331 });
332 }
333
335
353 inline std::unique_ptr<Image> Wiener(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset,
354 double noiseThreshold = 0.0)
355 {
356 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
357 return CVB_CALL_CAPI(FilterWiener(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
358 maskOffset.Y(), noiseThreshold, resimg));
359 });
360 }
361
363
381 inline std::unique_ptr<Image> Wiener(const Image &image, Size2D<int> maskSize, double noiseThreshold = 0.0)
382 {
383 return Wiener(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2), noiseThreshold);
384 }
385
387
399 {
400 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
401 if (orientation == FilterOrientation::Horizontal)
402 {
403 return CVB_CALL_CAPI(FilterPrewittHorizontal(image.Handle(), resimg));
404 }
405 else if (orientation == FilterOrientation::Vertical)
406 {
407 return CVB_CALL_CAPI(FilterPrewittVertical(image.Handle(), resimg));
408 }
409 else
410 {
411 throw std::invalid_argument("unknown filter orientation requested");
412 }
413 });
414 }
415
417
429 {
430 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
431 if (orientation == FilterOrientation::Horizontal)
432 {
433 return CVB_CALL_CAPI(FilterScharrHorizontal(image.Handle(), resimg));
434 }
435 else if (orientation == FilterOrientation::Vertical)
436 {
437 return CVB_CALL_CAPI(FilterScharrVertical(image.Handle(), resimg));
438 }
439 else
440 {
441 throw std::invalid_argument("unknown filter orientation requested");
442 }
443 });
444 }
445
447
461 {
462 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
463 if (orientation == FilterOrientation::Horizontal)
464 {
465 return CVB_CALL_CAPI(
466 FilterSobelHorizontal(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
467 }
468 else if (orientation == FilterOrientation::Vertical)
469 {
470 return CVB_CALL_CAPI(
471 FilterSobelVertical(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
472 }
473 else
474 {
475 throw std::invalid_argument("unknown filter orientation requested");
476 }
477 });
478 }
479
481
495 {
496 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
497 if (orientation == FilterOrientation::Horizontal)
498 {
499 return CVB_CALL_CAPI(
500 FilterSobelHorizontal2ndOrder(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
501 }
502 else if (orientation == FilterOrientation::Vertical)
503 {
504 return CVB_CALL_CAPI(
505 FilterSobelVertical2ndOrder(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
506 }
507 else
508 {
509 throw std::invalid_argument("unknown filter orientation requested");
510 }
511 });
512 }
513
515
527 {
528 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
529 return CVB_CALL_CAPI(FilterSobelCross(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
530 });
531 }
532
534
545 {
546 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
547 if (direction == RobertsDirection::Down)
548 {
549 return CVB_CALL_CAPI(FilterRobertsDown(image.Handle(), resimg));
550 }
551 else if (direction == RobertsDirection::Up)
552 {
553 return CVB_CALL_CAPI(FilterRobertsUp(image.Handle(), resimg));
554 }
555 else
556 {
557 throw std::invalid_argument("unknown filter direction requested");
558 }
559 });
560 }
561
562 } /* namespace Filter */
563
564 using Filter::EdgeFilter;
568
569 using Filter::BoxMax;
570 using Filter::BoxMean;
571 using Filter::BoxMedian;
572 using Filter::BoxMin;
573 using Filter::Canny;
575 using Filter::Gauss;
576 using Filter::HighPass;
577 using Filter::Laplace;
578 using Filter::LowPass;
579 using Filter::Prewitt;
580 using Filter::Roberts;
581 using Filter::Scharr;
582 using Filter::Sharpen;
583 using Filter::Sobel;
584 using Filter::Sobel2nd;
586 using Filter::Wiener;
587
588 } /* namespace Foundation */
589 CVB_END_INLINE_NS
590} /* namespace Cvb */
591
592#endif
The Common Vision Blox image.
Definition decl_image.hpp:45
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:232
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 FilterPrewittHorizontal(IMG ImgIn, IMG &ImgOut)
cvbres_t FilterBoxMedian(IMG ImgIn, long MaskWidth, long MaskHeight, long MaskOffsetX, long MaskOffsetY, IMG &ImgOut)
cvbres_t FilterSobelHorizontal2ndOrder(IMG ImgIn, TFilterMask MaskSize, IMG &ImgOut)
cvbres_t FilterBoxMax(IMG ImgIn, long MaskWidth, long MaskHeight, long MaskOffsetX, long MaskOffsetY, IMG &ImgOut)
cvbres_t FilterHiPass(IMG ImgIn, TFilterMask MaskSize, IMG &ImgOut)
cvbres_t FilterRobertsDown(IMG ImgIn, IMG &ImgOut)
cvbres_t FilterCanny(IMG ImgIn, long Index, TCannyEdgeFilter Filtering, long ThresholdLower, long ThresholdUpper, IMG &ImgOut)
cvbres_t FilterPrewittVertical(IMG ImgIn, IMG &ImgOut)
cvbres_t FilterGauss(IMG ImgIn, TFilterMask MaskSize, IMG &ImgOut)
cvbres_t FilterSobelHorizontal(IMG ImgIn, TFilterMask MaskSize, IMG &ImgOut)
cvbres_t FilterSobelVertical2ndOrder(IMG ImgIn, TFilterMask MaskSize, IMG &ImgOut)
cvbres_t FilterBoxMin(IMG ImgIn, long MaskWidth, long MaskHeight, long MaskOffsetX, long MaskOffsetY, IMG &ImgOut)
cvbres_t FilterSharpening(IMG ImgIn, IMG &ImgOut)
cvbres_t FilterWiener(IMG ImgIn, long MaskWidth, long MaskHeight, long MaskOffsetX, long MaskOffsetY, double NoiseThreshold, IMG &ImgOut)
cvbres_t FilterScharrHorizontal(IMG ImgIn, IMG &ImgOut)
cvbres_t FilterScharrVertical(IMG ImgIn, IMG &ImgOut)
cvbres_t FilterMedianColor(IMG ImgIn, TFilterMask MaskType, IMG &ImgOut)
cvbres_t FilterLoPass(IMG ImgIn, TFilterMask MaskSize, IMG &ImgOut)
cvbres_t FilterRobertsUp(IMG ImgIn, IMG &ImgOut)
cvbres_t FilterSobelCross(IMG ImgIn, TFilterMask MaskSize, IMG &ImgOut)
cvbres_t FilterBoxMean(IMG ImgIn, long MaskWidth, long MaskHeight, long MaskOffsetX, long MaskOffsetY, IMG &ImgOut)
cvbres_t FilterSobelVertical(IMG ImgIn, TFilterMask MaskSize, IMG &ImgOut)
Namespace for collection of filter functions from the Foundation package.
Definition filter.hpp:28
std::unique_ptr< Image > Roberts(const Image &image, Filter::RobertsDirection direction)
Apply a Roberts edge detector to the input image.
Definition filter.hpp:544
std::unique_ptr< Image > Laplace(const Image &image, Filter::FixedFilterSize size)
This function applies a square high pass Laplace filter to an image.
Definition filter.hpp:112
std::unique_ptr< Image > Sobel(const Image &image, Filter::FilterOrientation orientation, Filter::FixedFilterSize maskSize)
Applies a Sobel edge filter to the input image.
Definition filter.hpp:459
std::unique_ptr< Image > LowPass(const Image &image, Filter::FixedFilterSize size)
This function applies a square low pass filter to an image.
Definition filter.hpp:140
EdgeFilter
Edge filter modes. Currently only used by Canny().
Definition filter.hpp:58
@ Scharr
Scharr edge detection.
Definition filter.hpp:60
@ Sobel2nd
2nd order Sobel filter.
Definition filter.hpp:64
@ Sobel
1st order Sobel filter.
Definition filter.hpp:62
FilterOrientation
Orientation options for edge filters.
Definition filter.hpp:49
@ Vertical
Vertical.
Definition filter.hpp:53
@ Horizontal
Horizontal.
Definition filter.hpp:51
std::unique_ptr< Image > BoxMax(const Image &image, Size2D< int > maskSize, Point2D< int > maskOffset)
This function sets each pixel in the output image to the maximum value of all the input image pixels ...
Definition filter.hpp:258
std::unique_ptr< Image > BoxMedian(const Image &image, Size2D< int > maskSize, Point2D< int > maskOffset)
This function sets each pixel in the output image to the median value of all the input image pixels i...
Definition filter.hpp:293
std::unique_ptr< Image > Canny(const ImagePlane &imagePlane, Filter::EdgeFilter edgeFilter, int lowerThreshold, int upperThreshold)
Edge filter using the Canny algorithm.
Definition filter.hpp:94
std::unique_ptr< Image > BoxMin(const Image &image, Size2D< int > maskSize, Point2D< int > maskOffset)
This function sets each pixel in the output image to the minimum value of all the input image pixels ...
Definition filter.hpp:223
std::unique_ptr< Image > BoxMean(const Image &image, Size2D< int > maskSize, Point2D< int > maskOffset)
This function sets each pixel in the output image to the average of all the input image pixels in the...
Definition filter.hpp:188
std::unique_ptr< Image > HighPass(const Image &image, Filter::FixedFilterSize size)
This function applies a square high pass filter to an image.
Definition filter.hpp:155
std::unique_ptr< Image > Gauss(const Image &image, Filter::FixedFilterSize size)
This function applies a low high pass Gaussian filter to an image.
Definition filter.hpp:170
RobertsDirection
Directions of the Roberts edge filter.
Definition filter.hpp:69
@ Down
Filter for edges, that are positive when looking from the top left corner.
Definition filter.hpp:73
@ Up
Filter for edges, that are positive when looking from the top right corner.
Definition filter.hpp:71
std::unique_ptr< Image > Sharpen(const Image &image)
This function applies a Filter::FixedFilterSize::Kernel3x3 sharpen filter to an image.
Definition filter.hpp:126
std::unique_ptr< Image > ColorMedian(const Image &image, Filter::FixedFilterSize maskType)
Apply a color-correct box median filter to an RGB image.
Definition filter.hpp:327
std::unique_ptr< Image > Sobel2ndCross(const Image &image, Filter::FixedFilterSize maskSize)
Applies a 2nd order Sobel cross edge filter to the input image.
Definition filter.hpp:526
FixedFilterSize
Filter size values for filters using a fixed or discrete sized kernel.
Definition filter.hpp:38
@ Kernel5x5
Filter mask 5x5 pixels.
Definition filter.hpp:42
@ Kernel3x3
Filter mask 3x3 pixels.
Definition filter.hpp:40
@ Kernel7x7
Filter mask 7x7 pixels.
Definition filter.hpp:44
std::unique_ptr< Image > Prewitt(const Image &image, Filter::FilterOrientation orientation)
Applies a Prewitt edge filter to the input image.
Definition filter.hpp:398
std::unique_ptr< Image > Scharr(const Image &image, Filter::FilterOrientation orientation)
Applies a Scharr edge filter to the input image.
Definition filter.hpp:428
std::unique_ptr< Image > Wiener(const Image &image, Size2D< int > maskSize, Point2D< int > maskOffset, double noiseThreshold=0.0)
This function performs adaptive filtering of an image degraded by constant power additive noise.
Definition filter.hpp:353
std::unique_ptr< Image > Sobel2nd(const Image &image, Filter::FilterOrientation orientation, Filter::FixedFilterSize maskSize)
Applies a 2nd order Sobel edge filter to the input image.
Definition filter.hpp:493
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