IDS peak IPL v1.16.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
26namespace peak
27{
28namespace ipl
29{
30
34class Histogram final
35{
36public:
41 {
42 uint64_t PixelSum;
43 uint64_t PixelCount;
44 std::vector<uint64_t> Bins;
45 };
46
47public:
48 Histogram() = delete;
61 explicit Histogram(const Image& image);
62
69 ~Histogram();
70
82 Histogram(const Histogram& other);
83
95 Histogram& operator=(const Histogram& other);
96
105 Histogram(Histogram&& other) noexcept;
106
115 Histogram& operator=(Histogram&& other) noexcept;
116
127
137 PEAK_IPL_NO_DISCARD std::vector<HistogramChannel> Channels() const;
138
139private:
140 PEAK_IPL_HISTOGRAM_HANDLE m_backendHandle{};
141};
142
143inline Histogram::Histogram(const Image& image)
144{
147 ImageBackendAccessor::BackendHandle(image), &m_backendHandle);
148 });
149}
150
152{
153 if (m_backendHandle)
154 {
156 }
157}
158
159inline Histogram::Histogram(const Histogram& other)
160{
161 if (other.m_backendHandle)
162 {
163 ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Acquire(other.m_backendHandle); });
164 }
165
166 m_backendHandle = other.m_backendHandle;
167}
168
170{
171 if (this != &other)
172 {
173 if (m_backendHandle)
174 {
176 }
177
178 if (other.m_backendHandle)
179 {
181 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Acquire(other.m_backendHandle); });
182 }
183 }
184
185 m_backendHandle = other.m_backendHandle;
186
187 return *this;
188}
189
190inline Histogram::Histogram(Histogram&& other) noexcept
191{
192 *this = std::move(other);
193}
194
195inline Histogram& Histogram::operator=(Histogram&& other) noexcept
196{
197 if (this != &other)
198 {
199 if (m_backendHandle != nullptr)
200 {
202 }
203
204 m_backendHandle = other.m_backendHandle;
205 other.m_backendHandle = nullptr;
206 }
207
208 return *this;
209}
210
212{
214
217 m_backendHandle, reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(&pixelFormatName));
218 });
219
220 return peak::ipl::PixelFormat{ pixelFormatName };
221}
222
223inline std::vector<Histogram::HistogramChannel> Histogram::Channels() const
224{
225 std::vector<HistogramChannel> channels;
226
227 size_t numChannels = 0;
229 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetNumChannels(m_backendHandle, &numChannels); });
230
231 for (size_t ch = 0; ch < numChannels; ++ch)
232 {
233 uint64_t pixelSum = 0;
235 return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetPixelSumForChannel(m_backendHandle, ch, &pixelSum);
236 });
237
238 uint64_t pixelCount = 0;
240 return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetPixelCountForChannel(m_backendHandle, ch, &pixelCount);
241 });
242
243 size_t binListSize = 0;
245 return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetBinsForChannel(m_backendHandle, ch, nullptr, &binListSize);
246 });
247 std::vector<uint64_t> binList(binListSize);
250 m_backendHandle, ch, binList.data(), &binListSize);
251 });
252
253 channels.emplace_back(HistogramChannel{ pixelSum, pixelCount, std::move(binList) });
254 }
255
256 return channels;
257}
258
259} /* namespace ipl */
260} /* namespace peak */
peak::ipl::PixelFormat PixelFormat() const
Returns the pixel format of the histogram.
Definition peak_ipl_histogram.hpp:211
std::vector< HistogramChannel > Channels() const
Returns a vector containing the bin list of each channel.
Definition peak_ipl_histogram.hpp:223
~Histogram()
Destructor for the Histogram instance.
Definition peak_ipl_histogram.hpp:151
Histogram & operator=(const Histogram &other)
Copy assigment for Histogram instance.
Definition peak_ipl_histogram.hpp:169
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:41
Represents a pixel format and its specific properties.
Definition peak_ipl_pixel_format.hpp:32
Definition peak_ipl_binning.hpp:25
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:39
@ Invalid
Invalid Pixel Format.
Definition peak_ipl_simple_types.hpp:40
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:182
The "peak::ipl" namespace contains the whole image processing library.
Definition peak_ipl_binning.hpp:23
#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:41
uint64_t PixelCount
Definition peak_ipl_histogram.hpp:43
std::vector< uint64_t > Bins
Definition peak_ipl_histogram.hpp:44
uint64_t PixelSum
Definition peak_ipl_histogram.hpp:42