IDS peak IPL  v1.4.0
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  ~Histogram();
61  Histogram(const Histogram& other) = delete;
62  Histogram& operator=(const Histogram& other) = delete;
63  Histogram(Histogram&& other);
64  Histogram& operator=(Histogram&& other);
65 
76 
88  std::vector<HistogramChannel> Channels() const;
89 
90 private:
91  PEAK_IPL_HISTOGRAM_HANDLE m_backendHandle{};
92 };
93 
94 inline Histogram::Histogram(const Image& image)
95 {
98  ImageBackendAccessor::BackendHandle(image), &m_backendHandle);
99  });
100 }
101 
103 {
104  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Destruct(m_backendHandle);
105 }
106 
108 {
109  *this = std::move(other);
110 }
111 
113 {
114  if (this != &other)
115  {
116  (void)PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_Destruct(m_backendHandle);
117  m_backendHandle = other.m_backendHandle;
118  other.m_backendHandle = nullptr;
119  }
120 
121  return *this;
122 }
123 
125 {
126  PixelFormatName pixelFormatName = PixelFormatName::Invalid;
127 
130  m_backendHandle, reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(&pixelFormatName));
131  });
132 
133  return peak::ipl::PixelFormat{ pixelFormatName };
134 }
135 
136 inline std::vector<Histogram::HistogramChannel> Histogram::Channels() const
137 {
138  std::vector<HistogramChannel> channels;
139 
140  size_t numChannels = 0;
142  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetNumChannels(m_backendHandle, &numChannels); });
143 
144  for (size_t ch = 0; ch < numChannels; ++ch)
145  {
146  uint64_t pixelSum = 0;
148  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetPixelSumForChannel(m_backendHandle, ch, &pixelSum);
149  });
150 
151  uint64_t pixelCount = 0;
153  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetPixelCountForChannel(m_backendHandle, ch, &pixelCount);
154  });
155 
156  size_t binListSize = 0;
158  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Histogram_GetBinsForChannel(m_backendHandle, ch, nullptr, &binListSize);
159  });
160  std::vector<uint64_t> binList(binListSize);
163  m_backendHandle, ch, binList.data(), &binListSize);
164  });
165 
166  channels.emplace_back(HistogramChannel{ pixelSum, pixelCount, std::move(binList) });
167  }
168 
169  return channels;
170 }
171 
172 } /* namespace ipl */
173 } /* namespace peak */
uint64_t PixelSum
Definition: peak_ipl_histogram.hpp:42
struct PEAK_IPL_HISTOGRAM * PEAK_IPL_HISTOGRAM_HANDLE
Definition: peak_ipl_backend.h:242
#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:16
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:128
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:37
Stores the values of the histogram.
Definition: peak_ipl_histogram.hpp:40
~Histogram()
Definition: peak_ipl_histogram.hpp:102
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.
Histogram & operator=(const Histogram &other)=delete
std::vector< HistogramChannel > Channels() const
Returns a vector containing the bin list of each channel.
Definition: peak_ipl_histogram.hpp:136
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::PixelFormat PixelFormat() const
Returns the pixel format of the histogram.
Definition: peak_ipl_histogram.hpp:124
uint64_t PixelCount
Definition: peak_ipl_histogram.hpp:43
Represents a pixel format and its specific properties.
Definition: peak_ipl_pixel_format.hpp:31