IDSpeakIPL  v1.9.1
peak_ipl_histogram.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <utility>
21 #include <vector>
22 
26 namespace peak
27 {
28 namespace ipl
29 {
30 
34 class Histogram final
35 {
36 public:
41  {
42  uint64_t PixelSum;
43  uint64_t PixelCount;
44  std::vector<uint64_t> Bins;
45  };
46 
47 public:
48  Histogram() = delete;
59  explicit Histogram(const Image& image);
60 
67  ~Histogram();
68 
80  Histogram(const Histogram& other);
81 
93  Histogram& operator=(const Histogram& other);
94 
103  Histogram(Histogram&& other) noexcept;
104 
113  Histogram& operator=(Histogram&& other) noexcept;
114 
125 
135  PEAK_IPL_NO_DISCARD std::vector<HistogramChannel> Channels() const;
136 
137 private:
138  PEAK_IPL_HISTOGRAM_HANDLE m_backendHandle{};
139 };
140 
141 inline Histogram::Histogram(const Image& image)
142 {
145  ImageBackendAccessor::BackendHandle(image), &m_backendHandle);
146  });
147 }
148 
150 {
151  if (m_backendHandle)
152  {
153  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Destruct(m_backendHandle);
154  }
155 }
156 
157 inline Histogram::Histogram(const Histogram& other)
158 {
159  if (other.m_backendHandle)
160  {
161  ExecuteAndMapReturnCodes([&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Acquire(other.m_backendHandle); });
162  }
163 
164  m_backendHandle = other.m_backendHandle;
165 }
166 
168 {
169  if (this != &other)
170  {
171  if (m_backendHandle)
172  {
173  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Destruct(m_backendHandle);
174  }
175 
176  if (other.m_backendHandle)
177  {
179  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Acquire(other.m_backendHandle); });
180  }
181  }
182 
183  m_backendHandle = other.m_backendHandle;
184 
185  return *this;
186 }
187 
188 inline Histogram::Histogram(Histogram&& other) noexcept
189 {
190  *this = std::move(other);
191 }
192 
193 inline Histogram& Histogram::operator=(Histogram&& other) noexcept
194 {
195  if (this != &other)
196  {
197  if (m_backendHandle != nullptr)
198  {
199  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Destruct(m_backendHandle);
200  }
201 
202  m_backendHandle = other.m_backendHandle;
203  other.m_backendHandle = nullptr;
204  }
205 
206  return *this;
207 }
208 
210 {
211  PixelFormatName pixelFormatName = PixelFormatName::Invalid;
212 
215  m_backendHandle, reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(&pixelFormatName));
216  });
217 
218  return peak::ipl::PixelFormat{ pixelFormatName };
219 }
220 
221 inline std::vector<Histogram::HistogramChannel> Histogram::Channels() const
222 {
223  std::vector<HistogramChannel> channels;
224 
225  size_t numChannels = 0;
227  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetNumChannels(m_backendHandle, &numChannels); });
228 
229  for (size_t ch = 0; ch < numChannels; ++ch)
230  {
231  uint64_t pixelSum = 0;
233  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetPixelSumForChannel(m_backendHandle, ch, &pixelSum);
234  });
235 
236  uint64_t pixelCount = 0;
238  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetPixelCountForChannel(m_backendHandle, ch, &pixelCount);
239  });
240 
241  size_t binListSize = 0;
243  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetBinsForChannel(m_backendHandle, ch, nullptr, &binListSize);
244  });
245  std::vector<uint64_t> binList(binListSize);
248  m_backendHandle, ch, binList.data(), &binListSize);
249  });
250 
251  channels.emplace_back(HistogramChannel{ pixelSum, pixelCount, std::move(binList) });
252  }
253 
254  return channels;
255 }
256 
257 } /* namespace ipl */
258 } /* namespace peak */
#define PEAK_IPL_NO_DISCARD
Definition: peak_ipl_backend.h:26
uint64_t PixelSum
Definition: peak_ipl_histogram.hpp:42
struct PEAK_IPL_HISTOGRAM * PEAK_IPL_HISTOGRAM_HANDLE
Definition: peak_ipl_backend.h:361
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
PixelFormatName
Enum holding the possible pixel format names.
Definition: peak_ipl_simple_types.hpp:38
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_binning.hpp:22
std::vector< uint64_t > Bins
Definition: peak_ipl_histogram.hpp:44
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.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:182
PEAK_IPL_C_API PEAK_IPL_Histogram_GetNumChannels(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle, size_t *numChannels)
Queries the number of the given histogram&#39;s channels.
Stores the pixel format, width and height of an image and the pointer to the image buffer...
Definition: peak_ipl_image.hpp:39
Stores the values of the histogram.
Definition: peak_ipl_histogram.hpp:40
PEAK_IPL_C_API PEAK_IPL_Histogram_Acquire(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle)
Increase the reference count of a histogram object.
~Histogram()
Destructor for the Histogram instance.
Definition: peak_ipl_histogram.hpp:149
Histogram & operator=(const Histogram &other)
Copy assigment for Histogram instance.
Definition: peak_ipl_histogram.hpp:167
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_Destruct(PEAK_IPL_HISTOGRAM_HANDLE histogramHandle)
Destroys the histogram associated with the given handle.
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_NO_DISCARD std::vector< HistogramChannel > Channels() const
Returns a vector containing the bin list of each channel.
Definition: peak_ipl_histogram.hpp:221
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.
Stores the histogram values.
Definition: peak_ipl_histogram.hpp:34
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_NO_DISCARD peak::ipl::PixelFormat PixelFormat() const
Returns the pixel format of the histogram.
Definition: peak_ipl_histogram.hpp:209
uint64_t PixelCount
Definition: peak_ipl_histogram.hpp:43
Represents a pixel format and its specific properties.
Definition: peak_ipl_pixel_format.hpp:31