IDS peak IPL v1.17.1
Loading...
Searching...
No Matches
peak_ipl_histogram.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
17
18#include <cstddef>
19#include <cstdint>
20#include <utility>
21#include <vector>
22
27
28namespace peak
29{
30namespace ipl
31{
32
37class Histogram final
38{
39public:
44 {
45 uint64_t PixelSum;
46 uint64_t PixelCount;
47 std::vector<uint64_t> Bins;
48 };
49
50public:
51 Histogram() = delete;
64 explicit Histogram(const Image& image);
65
72 ~Histogram();
73
85 Histogram(const Histogram& other);
86
98 Histogram& operator=(const Histogram& other);
99
108 Histogram(Histogram&& other) noexcept;
109
118 Histogram& operator=(Histogram&& other) noexcept;
119
130
140 PEAK_IPL_NO_DISCARD std::vector<HistogramChannel> Channels() const;
141
142private:
143 PEAK_IPL_HISTOGRAM_HANDLE m_backendHandle{};
144};
145
146inline Histogram::Histogram(const Image& image)
147{
150 ImageBackendAccessor::BackendHandle(image), &m_backendHandle);
151 });
152}
153
155{
156 if (m_backendHandle)
157 {
159 }
160}
161
162inline Histogram::Histogram(const Histogram& other)
163{
164 if (other.m_backendHandle)
165 {
166 ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Acquire(other.m_backendHandle); });
167 }
168
169 m_backendHandle = other.m_backendHandle;
170}
171
173{
174 if (this != &other)
175 {
176 if (m_backendHandle)
177 {
179 }
180
181 if (other.m_backendHandle)
182 {
184 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Acquire(other.m_backendHandle); });
185 }
186 }
187
188 m_backendHandle = other.m_backendHandle;
189
190 return *this;
191}
192
193inline Histogram::Histogram(Histogram&& other) noexcept
194{
195 *this = std::move(other);
196}
197
198inline Histogram& Histogram::operator=(Histogram&& other) noexcept
199{
200 if (this != &other)
201 {
202 if (m_backendHandle != nullptr)
203 {
205 }
206
207 m_backendHandle = other.m_backendHandle;
208 other.m_backendHandle = nullptr;
209 }
210
211 return *this;
212}
213
215{
217
220 m_backendHandle, reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(&pixelFormatName));
221 });
222
223 return peak::ipl::PixelFormat{ pixelFormatName };
224}
225
226inline std::vector<Histogram::HistogramChannel> Histogram::Channels() const
227{
228 std::vector<HistogramChannel> channels;
229
230 size_t numChannels = 0;
232 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetNumChannels(m_backendHandle, &numChannels); });
233
234 for (size_t ch = 0; ch < numChannels; ++ch)
235 {
236 uint64_t pixelSum = 0;
238 return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetPixelSumForChannel(m_backendHandle, ch, &pixelSum);
239 });
240
241 uint64_t pixelCount = 0;
243 return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetPixelCountForChannel(m_backendHandle, ch, &pixelCount);
244 });
245
246 size_t binListSize = 0;
248 return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetBinsForChannel(m_backendHandle, ch, nullptr, &binListSize);
249 });
250 std::vector<uint64_t> binList(binListSize);
253 m_backendHandle, ch, binList.data(), &binListSize);
254 });
255
256 channels.emplace_back(HistogramChannel{ pixelSum, pixelCount, std::move(binList) });
257 }
258
259 return channels;
260}
261
262} /* namespace ipl */
263} /* namespace peak */
peak::ipl::PixelFormat PixelFormat() const
Returns the pixel format of the histogram.
Definition peak_ipl_histogram.hpp:214
std::vector< HistogramChannel > Channels() const
Returns a vector containing the bin list of each channel.
Definition peak_ipl_histogram.hpp:226
~Histogram()
Destructor for the Histogram instance.
Definition peak_ipl_histogram.hpp:154
Histogram & operator=(const Histogram &other)
Copy assigment for Histogram instance.
Definition peak_ipl_histogram.hpp:172
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:47
Represents a pixel format and its specific properties.
Definition peak_ipl_pixel_format.hpp:35
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:43
@ Invalid
Invalid Pixel Format.
Definition peak_ipl_simple_types.hpp:44
The "peak::ipl" namespace contains the whole image processing library.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:282
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:25
PEAK_IPL_C_API PEAK_IPL_Histogram_Destruct(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle)
Destroys the histogram associated with the given handle.
PEAK_IPL_C_API PEAK_IPL_Histogram_Construct(PEAK_IPL_IMAGE_HANDLE imageHandle, PEAK_IPL_HISTOGRAM_HANDLE *histogramHandle)
Creates a histogram from image data.
PEAK_IPL_C_API PEAK_IPL_Histogram_GetPixelFormat(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle, PEAK_IPL_PIXEL_FORMAT *pixelFormat)
Queries the pixel format of the given histogram.
struct PEAK_IPL_HISTOGRAM * PEAK_IPL_HISTOGRAM_HANDLE
Definition peak_ipl_backend.h:409
PEAK_IPL_C_API PEAK_IPL_Histogram_Acquire(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle)
Increase the reference count of a histogram object.
PEAK_IPL_C_API PEAK_IPL_Histogram_GetNumChannels(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle, size_t *numChannels)
Queries the number of the given histogram's channels.
PEAK_IPL_C_API PEAK_IPL_Histogram_GetPixelSumForChannel(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle, size_t channelIndex, uint64_t *pixelSum)
Queries the pixel sum for the channel with the given index.
PEAK_IPL_C_API PEAK_IPL_Histogram_GetBinsForChannel(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle, size_t channelIndex, uint64_t *bins, size_t *binsSize)
Queries the bin list of the channel with the given index.
PEAK_IPL_C_API PEAK_IPL_Histogram_GetPixelCountForChannel(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle, size_t channelIndex, uint64_t *pixelCount)
Queries the pixel count for the channel with the given index.
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:173
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:16
Stores the values of the histogram.
Definition peak_ipl_histogram.hpp:44
uint64_t PixelCount
Definition peak_ipl_histogram.hpp:46
std::vector< uint64_t > Bins
Definition peak_ipl_histogram.hpp:47
uint64_t PixelSum
Definition peak_ipl_histogram.hpp:45