CVB++ 15.0
analyze.hpp
1#pragma once
2
3#include <vector>
4
5#include "global.hpp"
6#include "image_plane.hpp"
7#include "area_2d.hpp"
8#include "local_maximum.hpp"
9#include "_detail/detail_pixel_list.hpp"
10
11namespace Cvb
12{
13
15 CVB_BEGIN_INLINE_NS
17
19
30 inline std::vector<int> Histogram(const ImagePlane &plane, Area2D aoi, double density = 1.0)
31 {
32 const size_t size = 256;
33 Cvb::CExports::cvbval_t histogram[size] = {0};
34 if (!CVB_CALL_CAPI(ImageHistogram(plane.Parent().Handle(), static_cast<CExports::cvbdim_t>(plane.Plane()),
35 static_cast<CExports::cvbdensity_t>(density * 1.000),
36 *reinterpret_cast<CExports::TArea *>(&aoi),
37 reinterpret_cast<Cvb::CExports::cvbval_t *>(histogram))))
38 Utilities::SystemInfo::ThrowLastError();
39 return std::vector<int>(histogram, histogram + size);
40 }
41
43
53 inline std::vector<int> Histogram(const ImagePlane &plane, double density = 1.0)
54 {
55 Area2D aoi(static_cast<Rect<double>>(plane.Parent().Bounds()), plane.Parent().CoordinateSystem());
56 return Histogram(plane, aoi, density);
57 }
58
60
71 inline std::vector<LocalMaximum> FindLocalMaxima(const ImagePlane &plane, int locality, double threshold,
72 Rect<int> aoi)
73 {
74 CExports::PIXELLIST handle = nullptr;
75 if (!CVB_CALL_CAPI(
76 FindMaximaEx(plane.Parent().Handle(), static_cast<CExports::cvbdim_t>(plane.Plane()),
77 static_cast<CExports::cvbdim_t>(aoi.Left()), static_cast<CExports::cvbdim_t>(aoi.Top()),
78 static_cast<CExports::cvbdim_t>(aoi.Right()), static_cast<CExports::cvbdim_t>(aoi.Bottom()),
79 static_cast<CExports::cvbdim_t>(locality), threshold, handle)))
80 Utilities::SystemInfo::ThrowLastError();
81
82 auto pixelList = Internal::PixelList::FromHandle(HandleGuard<Internal::PixelList>(handle));
83 return pixelList->ToLocalMaximum();
84 }
85
87
97 inline std::vector<LocalMaximum> FindLocalMaxima(const ImagePlane &plane, int locality, double threshold)
98 {
99 return FindLocalMaxima(plane, locality, threshold, plane.Parent().Bounds());
100 }
101
103
119 inline std::vector<LocalMaximum> FindLocalMaxima(const ImagePlane &plane, int locality, double threshold,
120 SubPixelMode mode, Neighborhood radius, Rect<int> aoi)
121 {
122 CExports::PIXELLIST handle = nullptr;
123 if (!CVB_CALL_CAPI(FindSubPixelMaxima(
124 plane.Parent().Handle(), static_cast<CExports::cvbdim_t>(plane.Plane()),
125 static_cast<CExports::cvbdim_t>(aoi.Left()), static_cast<CExports::cvbdim_t>(aoi.Top()),
126 static_cast<CExports::cvbdim_t>(aoi.Right()), static_cast<CExports::cvbdim_t>(aoi.Bottom()),
127 static_cast<CExports::cvbdim_t>(locality), threshold, static_cast<CExports::TSubPixelMode>(mode),
128 static_cast<CExports::cvbdim_t>(radius), handle)))
129 Utilities::SystemInfo::ThrowLastError();
130
131 auto pixelList = Internal::PixelList::FromHandle(HandleGuard<Internal::PixelList>(handle));
132 return pixelList->ToLocalMaximum();
133 }
134
136
151 inline std::vector<LocalMaximum> FindLocalMaxima(const ImagePlane &plane, int locality, double threshold,
152 SubPixelMode mode, Neighborhood radius)
153 {
154 return FindLocalMaxima(plane, locality, threshold, mode, radius, plane.Parent().Bounds());
155 }
156
157 CVB_END_INLINE_NS
158
159} // namespace Cvb
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
AffineMatrix2D CoordinateSystem() const noexcept
Get the coordinate system of the image.
Definition decl_image.hpp:547
Rect< int > Bounds() const noexcept
Bounding rectangle of the image in pixels.
Definition decl_image.hpp:438
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
std::vector< LocalMaximum > FindLocalMaxima(const ImagePlane &plane, int locality, double threshold, SubPixelMode mode, Neighborhood radius, Rect< int > aoi)
Find sub pixel accurate local maxima in the input image.
Definition analyze.hpp:119
std::vector< int > Histogram(const ImagePlane &plane, double density=1.0)
Gather and return the histogram from an 8 bits per pixel unsigned image.
Definition analyze.hpp:53
std::vector< LocalMaximum > FindLocalMaxima(const ImagePlane &plane, int locality, double threshold, SubPixelMode mode, Neighborhood radius)
Find sub pixel accurate local maxima in the input image.
Definition analyze.hpp:151
std::vector< int > Histogram(const ImagePlane &plane, Area2D aoi, double density=1.0)
Gather and return the histogram from an 8 bits per pixel unsigned image.
Definition analyze.hpp:30
std::vector< LocalMaximum > FindLocalMaxima(const ImagePlane &plane, int locality, double threshold)
Find local maxima in the input image.
Definition analyze.hpp:97
std::vector< LocalMaximum > FindLocalMaxima(const ImagePlane &plane, int locality, double threshold, Rect< int > aoi)
Find local maxima in the input image.
Definition analyze.hpp:71
ImagePlane(const class Plane &plane)
Implicitly convert a plane to an image plane.
Definition detail_image_plane.hpp:26
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
Rectangle object.
Definition rect.hpp:24
cvbbool_t FindMaximaEx(IMG Image, cvbval_t PlaneIndex, cvbval_t Left, cvbval_t Top, cvbval_t Right, cvbval_t Bottom, cvbval_t Locality, double Threshold, PIXELLIST &MaximaList)
cvbbool_t ImageHistogram(IMG Image, cvbval_t PlaneIndex, cvbdensity_t Density, TArea Area, THistogram &Histogram)
cvbbool_t FindSubPixelMaxima(IMG Image, cvbdim_t PlaneIndex, cvbdim_t Left, cvbdim_t Top, cvbdim_t Right, cvbdim_t Bottom, cvbdim_t Locality, double Threshold, TSubPixelMode SubPixelMode, cvbdim_t Radius, PIXELLIST &MaximaList)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
SubPixelMode
Method for determining sub pixel accuracy when working with the FindLocalMaxima functions.
Definition global.hpp:312
std::vector< int > Histogram(const ImagePlane &plane, Area2D aoi, double density=1.0)
Gather and return the histogram from an 8 bits per pixel unsigned image.
Definition analyze.hpp:30
std::vector< LocalMaximum > FindLocalMaxima(const ImagePlane &plane, int locality, double threshold, Rect< int > aoi)
Find local maxima in the input image.
Definition analyze.hpp:71
Neighborhood
Neighborhood to use in sub pixel calculation of local maxima.
Definition global.hpp:337