CVB++ 15.1
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
32 namespace Filter
33 {
34
36
42 enum class FixedFilterSize
43 {
45 Kernel3x3 = CExports::FM_3x3,
47 Kernel5x5 = CExports::FM_5x5,
49 Kernel7x7 = CExports::FM_7x7
50 };
51
60
62 enum class EdgeFilter
63 {
65 Scharr = CExports::CE_Scharr,
67 Sobel = CExports::CE_Sobel,
69 Sobel2nd = CExports::CE_Sobel2nd
70 };
71
74 {
79 };
80
82
99 inline std::unique_ptr<Image> Canny(const ImagePlane &imagePlane, Filter::EdgeFilter edgeFilter,
100 int lowerThreshold, int upperThreshold)
101 {
102 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
103 return CVB_CALL_CAPI(FilterCanny(imagePlane.Parent().Handle(), imagePlane.Plane(),
104 static_cast<CExports::TCannyEdgeFilter>(edgeFilter), lowerThreshold,
105 upperThreshold, resimg));
106 });
107 }
108
110
118 {
119 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
120 return CVB_CALL_CAPI(FilterLaplace(image.Handle(), static_cast<CExports::TFilterMask>(size), resimg));
121 });
122 }
123
125
132 {
133 return Internal::DoResCallObjectOut<Image>(
134 [&](void *&resimg) { return CVB_CALL_CAPI(FilterSharpening(image.Handle(), resimg)); });
135 }
136
138
146 {
147 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
148 return CVB_CALL_CAPI(FilterLoPass(image.Handle(), static_cast<CExports::TFilterMask>(size), resimg));
149 });
150 }
151
153
161 {
162 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
163 return CVB_CALL_CAPI(FilterHiPass(image.Handle(), static_cast<CExports::TFilterMask>(size), resimg));
164 });
165 }
166
168
176 {
177 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
178 return CVB_CALL_CAPI(FilterGauss(image.Handle(), static_cast<CExports::TFilterMask>(size), resimg));
179 });
180 }
181
184
193 inline std::unique_ptr<Image> BoxMean(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset)
194 {
195 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
196 return CVB_CALL_CAPI(FilterBoxMean(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
197 maskOffset.Y(), resimg));
198 });
199 }
200
203
212 inline std::unique_ptr<Image> BoxMean(const Image &image, Size2D<int> maskSize)
213 {
214 return BoxMean(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
215 }
216
219
228 inline std::unique_ptr<Image> BoxMin(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset)
229 {
230 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
231 return CVB_CALL_CAPI(FilterBoxMin(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
232 maskOffset.Y(), resimg));
233 });
234 }
235
238
247 inline std::unique_ptr<Image> BoxMin(const Image &image, Size2D<int> maskSize)
248 {
249 return BoxMin(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
250 }
251
254
263 inline std::unique_ptr<Image> BoxMax(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset)
264 {
265 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
266 return CVB_CALL_CAPI(FilterBoxMax(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
267 maskOffset.Y(), resimg));
268 });
269 }
270
273
282 inline std::unique_ptr<Image> BoxMax(const Image &image, Size2D<int> maskSize)
283 {
284 return BoxMax(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
285 }
286
289
298 inline std::unique_ptr<Image> BoxMedian(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset)
299 {
300 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
301 return CVB_CALL_CAPI(FilterBoxMedian(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
302 maskOffset.Y(), resimg));
303 });
304 }
305
308
317 inline std::unique_ptr<Image> BoxMedian(const Image &image, Size2D<int> maskSize)
318 {
319 return BoxMedian(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2));
320 }
321
323
333 {
334 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
335 return CVB_CALL_CAPI(FilterMedianColor(image.Handle(), static_cast<CExports::TFilterMask>(maskType), resimg));
336 });
337 }
338
340
358 inline std::unique_ptr<Image> Wiener(const Image &image, Size2D<int> maskSize, Point2D<int> maskOffset,
359 double noiseThreshold = 0.0)
360 {
361 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
362 return CVB_CALL_CAPI(FilterWiener(image.Handle(), maskSize.Width(), maskSize.Height(), maskOffset.X(),
363 maskOffset.Y(), noiseThreshold, resimg));
364 });
365 }
366
368
386 inline std::unique_ptr<Image> Wiener(const Image &image, Size2D<int> maskSize, double noiseThreshold = 0.0)
387 {
388 return Wiener(image, maskSize, Point2D<int>(maskSize.Width() / 2, maskSize.Height() / 2), noiseThreshold);
389 }
390
392
404 {
405 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
406 if (orientation == FilterOrientation::Horizontal)
407 {
408 return CVB_CALL_CAPI(FilterPrewittHorizontal(image.Handle(), resimg));
409 }
410 else if (orientation == FilterOrientation::Vertical)
411 {
412 return CVB_CALL_CAPI(FilterPrewittVertical(image.Handle(), resimg));
413 }
414 else
415 {
416 throw std::invalid_argument("unknown filter orientation requested");
417 }
418 });
419 }
420
422
434 {
435 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
436 if (orientation == FilterOrientation::Horizontal)
437 {
438 return CVB_CALL_CAPI(FilterScharrHorizontal(image.Handle(), resimg));
439 }
440 else if (orientation == FilterOrientation::Vertical)
441 {
442 return CVB_CALL_CAPI(FilterScharrVertical(image.Handle(), resimg));
443 }
444 else
445 {
446 throw std::invalid_argument("unknown filter orientation requested");
447 }
448 });
449 }
450
452
466 {
467 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
468 if (orientation == FilterOrientation::Horizontal)
469 {
470 return CVB_CALL_CAPI(
471 FilterSobelHorizontal(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
472 }
473 else if (orientation == FilterOrientation::Vertical)
474 {
475 return CVB_CALL_CAPI(
476 FilterSobelVertical(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
477 }
478 else
479 {
480 throw std::invalid_argument("unknown filter orientation requested");
481 }
482 });
483 }
484
486
500 {
501 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
502 if (orientation == FilterOrientation::Horizontal)
503 {
504 return CVB_CALL_CAPI(
505 FilterSobelHorizontal2ndOrder(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
506 }
507 else if (orientation == FilterOrientation::Vertical)
508 {
509 return CVB_CALL_CAPI(
510 FilterSobelVertical2ndOrder(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
511 }
512 else
513 {
514 throw std::invalid_argument("unknown filter orientation requested");
515 }
516 });
517 }
518
520
532 {
533 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
534 return CVB_CALL_CAPI(FilterSobelCross(image.Handle(), static_cast<CExports::TFilterMask>(maskSize), resimg));
535 });
536 }
537
539
550 {
551 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
552 if (direction == RobertsDirection::Down)
553 {
554 return CVB_CALL_CAPI(FilterRobertsDown(image.Handle(), resimg));
555 }
556 else if (direction == RobertsDirection::Up)
557 {
558 return CVB_CALL_CAPI(FilterRobertsUp(image.Handle(), resimg));
559 }
560 else
561 {
562 throw std::invalid_argument("unknown filter direction requested");
563 }
564 });
565 }
566
567 } /* namespace Filter */
568
569 using Filter::EdgeFilter;
573
574 using Filter::BoxMax;
575 using Filter::BoxMean;
576 using Filter::BoxMedian;
577 using Filter::BoxMin;
578 using Filter::Canny;
580 using Filter::Gauss;
581 using Filter::HighPass;
582 using Filter::Laplace;
583 using Filter::LowPass;
584 using Filter::Prewitt;
585 using Filter::Roberts;
586 using Filter::Scharr;
587 using Filter::Sharpen;
588 using Filter::Sobel;
589 using Filter::Sobel2nd;
591 using Filter::Wiener;
592
593 } /* namespace Foundation */
594 CVB_END_INLINE_NS
595} /* namespace Cvb */
596
597#endif
The Common Vision Blox image.
Definition decl_image.hpp:50
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 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:33
std::unique_ptr< Image > Roberts(const Image &image, Filter::RobertsDirection direction)
Apply a Roberts edge detector to the input image.
Definition filter.hpp:549
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:117
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:464
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:145
EdgeFilter
Edge filter modes. Currently only used by Canny().
Definition filter.hpp:63
@ Scharr
Scharr edge detection.
Definition filter.hpp:65
@ Sobel2nd
2nd order Sobel filter.
Definition filter.hpp:69
@ Sobel
1st order Sobel filter.
Definition filter.hpp:67
FilterOrientation
Orientation options for edge filters.
Definition filter.hpp:54
@ Vertical
Vertical.
Definition filter.hpp:58
@ Horizontal
Horizontal.
Definition filter.hpp:56
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:263
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:298
std::unique_ptr< Image > Canny(const ImagePlane &imagePlane, Filter::EdgeFilter edgeFilter, int lowerThreshold, int upperThreshold)
Edge filter using the Canny algorithm.
Definition filter.hpp:99
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:228
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:193
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:160
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:175
RobertsDirection
Directions of the Roberts edge filter.
Definition filter.hpp:74
@ Down
Filter for edges, that are positive when looking from the top left corner.
Definition filter.hpp:78
@ Up
Filter for edges, that are positive when looking from the top right corner.
Definition filter.hpp:76
std::unique_ptr< Image > Sharpen(const Image &image)
This function applies a Filter::FixedFilterSize::Kernel3x3 sharpen filter to an image.
Definition filter.hpp:131
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:332
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:531
FixedFilterSize
Filter size values for filters using a fixed or discrete sized kernel.
Definition filter.hpp:43
@ Kernel5x5
Filter mask 5x5 pixels.
Definition filter.hpp:47
@ Kernel3x3
Filter mask 3x3 pixels.
Definition filter.hpp:45
@ Kernel7x7
Filter mask 7x7 pixels.
Definition filter.hpp:49
std::unique_ptr< Image > Prewitt(const Image &image, Filter::FilterOrientation orientation)
Applies a Prewitt edge filter to the input image.
Definition filter.hpp:403
std::unique_ptr< Image > Scharr(const Image &image, Filter::FilterOrientation orientation)
Applies a Scharr edge filter to the input image.
Definition filter.hpp:433
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:358
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:498
Namespace for the Foundation package.
Definition decl_metric_aqs12_calibration_piece.hpp:11
Root namespace for the Image Manager interface.
Definition version.hpp:11