IDS peak IPL v1.17.0
Loading...
Searching...
No Matches
peak_ipl_sharpness.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
18
19#include <type_traits>
20#include <algorithm>
21#include <cstdint>
22#include <iterator>
23#include <vector>
24
29
30namespace peak
31{
32namespace ipl
33{
34enum class PixelFormatName;
42class Sharpness final
43{
44public:
51 Sharpness();
52
59 ~Sharpness();
60
72 Sharpness(const Sharpness& other);
73
85 Sharpness& operator=(const Sharpness& other);
86
95 Sharpness(Sharpness&& other) noexcept;
96
105 Sharpness& operator=(Sharpness&& other) noexcept;
106
115
119 enum class SharpnessROIWeight : uint16_t
120 {
121 Weak = 0x0021,
122 Medium = 0x0042,
123 Strong = 0x0063
124 };
125
138
139 using SharpnessROIList = std::vector<SharpnessROI>;
140
154 inline double Measure(const Image& image);
155
164 PEAK_IPL_NO_DISCARD inline bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const;
165
172 PEAK_IPL_NO_DISCARD inline std::vector<PixelFormatName> SupportedPixelFormats() const;
173
179 inline void SetAlgorithm(SharpnessAlgorithm algorithm);
180
188
196
203 inline void SetROIs(const SharpnessROIList& rois);
204
211 inline void SetROI(const SharpnessROI& roi);
212
219 inline void SetROI(const Rect2D& roi);
220
228
229private:
230 PEAK_IPL_SHARPNESS_HANDLE m_backendHandle{};
231};
232
237
239{
240 if (m_backendHandle)
241 {
243 }
244}
245
246inline Sharpness::Sharpness(const Sharpness& other)
247{
248 if (other.m_backendHandle)
249 {
251 }
252
253 m_backendHandle = other.m_backendHandle;
254}
255
257{
258 if (this != &other)
259 {
260 if (m_backendHandle)
261 {
263 }
264
265 if (other.m_backendHandle)
266 {
268 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageSharpness_Acquire(other.m_backendHandle); });
269 }
270 }
271
272 m_backendHandle = other.m_backendHandle;
273
274 return *this;
275}
276
277inline Sharpness::Sharpness(Sharpness&& other) noexcept
278{
279 *this = std::move(other);
280}
281
282inline Sharpness& Sharpness::operator=(Sharpness&& other) noexcept
283{
284 if (this != &other)
285 {
286 if (m_backendHandle != nullptr)
287 {
289 }
290
291 m_backendHandle = other.m_backendHandle;
292 other.m_backendHandle = nullptr;
293 }
294
295 return *this;
296}
297
298inline double Sharpness::Measure(const Image& image)
299{
300 double calculated_value;
301
304 m_backendHandle, ImageBackendAccessor::BackendHandle(image), &calculated_value);
305 });
306
307 return calculated_value;
308}
309
310inline bool Sharpness::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
311{
312 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
313
316 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
317 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
318 });
319
320 return isPixelFormatSupported > 0;
321}
322
323inline std::vector<PixelFormatName> Sharpness::SupportedPixelFormats() const
324{
325 size_t sizeOfData{};
328 m_backendHandle, nullptr, &sizeOfData);
329 });
330
331 std::vector<PixelFormatName> formats(sizeOfData);
334 m_backendHandle, reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(formats.data()), &sizeOfData);
335 });
336
337 return formats;
338}
339
341{
344 m_backendHandle, static_cast<PEAK_IPL_SHARPNESS_ALGORITHM>(algorithm));
345 });
346}
347
349{
350 SharpnessAlgorithm algorithm;
351
354 m_backendHandle, reinterpret_cast<PEAK_IPL_SHARPNESS_ALGORITHM*>(&algorithm));
355 });
356
357 return algorithm;
358}
359
361{
362 PEAK_IPL_SIZE_2D size{};
363
365 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageSharpness_GetROIMinimumSize(m_backendHandle, &size); });
366
367 return Size2D{ size.width, size.height };
368}
369
370inline void Sharpness::SetROIs(const SharpnessROIList& rois)
371{
373 std::vector<PEAK_IPL_SHARPNESS_ROI> sharpness_rois{};
374
375 std::transform(std::cbegin(rois), std::cend(rois), std::back_inserter(sharpness_rois), [](const auto roi) {
376 return PEAK_IPL_SHARPNESS_ROI{ PEAK_IPL_RECT_2D{ { roi.rect.topLeft().x, roi.rect.topLeft().y },
377 { roi.rect.size().width, roi.rect.size().height } },
378 roi.xSamplingInterval, roi.ySamplingInterval,
379 static_cast<std::underlying_type_t<SharpnessROIWeight>>(roi.weight) };
380 });
381
383 m_backendHandle, sharpness_rois.data(), sharpness_rois.size());
384 });
385}
386
387inline void Sharpness::SetROI(const SharpnessROI& roi)
388{
389 SharpnessROIList rois{ roi };
390 SetROIs(rois);
391}
392
393inline void Sharpness::SetROI(const Rect2D& roi)
394{
395 SharpnessROI sharpnessRoi{ roi, 1, 1, SharpnessROIWeight::Medium };
396 SetROI(sharpnessRoi);
397}
398
400{
401 size_t roiListSize{};
403 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageSharpness_GetROIs(m_backendHandle, nullptr, &roiListSize); });
404
405 std::vector<PEAK_IPL_SHARPNESS_ROI> sharpness_rois(roiListSize);
408 m_backendHandle, sharpness_rois.data(), &roiListSize);
409 });
410
411 SharpnessROIList rois{};
412
413 std::transform(
414 std::cbegin(sharpness_rois), std::cend(sharpness_rois), std::back_inserter(rois), [](const auto roi) {
415 return SharpnessROI{ Rect2D{ roi.rect.position.x, roi.rect.position.y, roi.rect.size.width,
416 roi.rect.size.height },
417 roi.xSamplingInterval, roi.ySamplingInterval, static_cast<SharpnessROIWeight>(roi.weight) };
418 });
419
420 return rois;
421}
422
424{
425 return lhs.rect == rhs.rect && lhs.weight == rhs.weight && lhs.xSamplingInterval == rhs.xSamplingInterval
427}
428
430{
431 return !(lhs == rhs);
432}
433
434} /* namespace ipl */
435} /* namespace peak */
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:46
Rectangle type.
Definition peak_ipl_rect.hpp:32
Sharpness()
Constructor for a new Sharpness instance.
Definition peak_ipl_sharpness.hpp:233
Sharpness & operator=(const Sharpness &other)
Copy assigment for Sharpness instance.
Definition peak_ipl_sharpness.hpp:256
void SetROIs(const SharpnessROIList &rois)
Sets the region of interests in which the sharpness is measured.
Definition peak_ipl_sharpness.hpp:370
Size2D ROIMinSize() const
Gets the minimum size of a ROI, in which the sharpness is measured.
Definition peak_ipl_sharpness.hpp:360
void SetROI(const SharpnessROI &roi)
Set ROI in which the sharpness is measured.
Definition peak_ipl_sharpness.hpp:387
SharpnessAlgorithm
Measure Algorithms.
Definition peak_ipl_sharpness.hpp:109
@ HistogramVariance
statistics-based sharpness algorithm
Definition peak_ipl_sharpness.hpp:112
@ Tenengrad
contrast-based sharpness algorithm (convolution)
Definition peak_ipl_sharpness.hpp:110
@ Sobel
contrast-based sharpness algorithm (convolution)
Definition peak_ipl_sharpness.hpp:113
@ MeanScore
contrast-based sharpness algorithm (mean value)
Definition peak_ipl_sharpness.hpp:111
SharpnessROIList ROIs() const
Gets ROIs in which the sharpness is measured.
Definition peak_ipl_sharpness.hpp:399
double Measure(const Image &image)
Measures the sharpness of the given image. The higher the value, the better the sharpness.
Definition peak_ipl_sharpness.hpp:298
SharpnessROIWeight
Definition peak_ipl_sharpness.hpp:120
@ Weak
Weak use of roi for the measurement.
Definition peak_ipl_sharpness.hpp:121
@ Medium
Normal use of roi for the measurement.
Definition peak_ipl_sharpness.hpp:122
@ Strong
Strong use of roi for the measurement.
Definition peak_ipl_sharpness.hpp:123
std::vector< SharpnessROI > SharpnessROIList
Definition peak_ipl_sharpness.hpp:139
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Checks if the given pixel format can be used for sharpness measurement.
Definition peak_ipl_sharpness.hpp:310
~Sharpness()
Destructor for the Sharpness instance.
Definition peak_ipl_sharpness.hpp:238
void SetAlgorithm(SharpnessAlgorithm algorithm)
Sets the algorithm used for measurement calculation.
Definition peak_ipl_sharpness.hpp:340
SharpnessAlgorithm Algorithm() const
Returns the used algorithm for the sharpness measurement.
Definition peak_ipl_sharpness.hpp:348
std::vector< PixelFormatName > SupportedPixelFormats() const
Returns a list of supported pixel formats which can be used for sharpness measurement.
Definition peak_ipl_sharpness.hpp:323
The "peak::ipl" namespace contains the whole image processing library.
bool operator!=(const Sharpness::SharpnessROI &lhs, const Sharpness::SharpnessROI &rhs)
Definition peak_ipl_sharpness.hpp:429
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:41
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:271
bool operator==(const Sharpness::SharpnessROI &lhs, const Sharpness::SharpnessROI &rhs)
Definition peak_ipl_sharpness.hpp:423
#define PEAK_IPL_NO_DISCARD
Definition peak_ipl_attribute_defines.h:25
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_GetIsPixelFormatSupported(PEAK_IPL_SHARPNESS_HANDLE handle, PEAK_IPL_PIXEL_FORMAT pixelFormat, PEAK_IPL_BOOL8 *isPixelFormatSupported)
Asks the given sharpness measurement whether it supports the given pixel format.
uint16_t PEAK_IPL_SHARPNESS_ALGORITHM
Definition peak_ipl_backend.h:283
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_GetROIMinimumSize(PEAK_IPL_SHARPNESS_HANDLE handle, struct PEAK_IPL_SIZE_2D *min_size)
Returns the minimum size of a ROI to use for measurement calculation.
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_GetAlgorithm(PEAK_IPL_SHARPNESS_HANDLE handle, PEAK_IPL_SHARPNESS_ALGORITHM *algorithm)
Returns the algorithm to use for measurement calculation.
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_Acquire(PEAK_IPL_SHARPNESS_HANDLE handle)
Increase the reference count of a sharpness measurement object.
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_SetAlgorithm(PEAK_IPL_SHARPNESS_HANDLE handle, PEAK_IPL_SHARPNESS_ALGORITHM algorithm)
Sets the algorithm used for measurement calculation.
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_Destruct(PEAK_IPL_SHARPNESS_HANDLE handle)
Destroys the sharpness measurement associated with the given handle.
struct PEAK_IPL_SHARPNESS * PEAK_IPL_SHARPNESS_HANDLE
Definition peak_ipl_backend.h:421
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_SetROIs(PEAK_IPL_SHARPNESS_HANDLE handle, struct PEAK_IPL_SHARPNESS_ROI *roiList, size_t roiListSize)
Sets ROIs in which the sharpness is measured.
int8_t PEAK_IPL_BOOL8
Definition peak_ipl_backend.h:26
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_GetROIs(PEAK_IPL_SHARPNESS_HANDLE handle, struct PEAK_IPL_SHARPNESS_ROI *roiList, size_t *roiListSize)
Returns the ROIs in which the sharpness is measured.
int32_t PEAK_IPL_PIXEL_FORMAT
Definition peak_ipl_backend.h:173
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_Measure(PEAK_IPL_SHARPNESS_HANDLE handle, PEAK_IPL_IMAGE_HANDLE imageHandle, double *calculated_value)
Measures the relative sharpness of the given image.
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_Construct(PEAK_IPL_SHARPNESS_HANDLE *handle)
Creates a sharpness measurement.
PEAK_IPL_C_API PEAK_IPL_ImageSharpness_GetSupportedPixelFormatList(PEAK_IPL_SHARPNESS_HANDLE handle, PEAK_IPL_PIXEL_FORMAT *pixelFormatList, size_t *pixelFormatListSize)
Queries the supported pixel formats.
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:16
Definition peak_ipl_backend.h:271
Definition peak_ipl_backend.h:306
Definition peak_ipl_backend.h:265
Definition peak_ipl_sharpness.hpp:127
uint8_t ySamplingInterval
vertical sampling interval
Definition peak_ipl_sharpness.hpp:135
SharpnessROIWeight weight
weight for the roi
Definition peak_ipl_sharpness.hpp:136
uint8_t xSamplingInterval
horizontal sampling interval
Definition peak_ipl_sharpness.hpp:134
SharpnessROI(Rect2D rect, uint8_t xSamplingInterval, uint8_t ySamplingInterval, SharpnessROIWeight weight)
Definition peak_ipl_sharpness.hpp:130
Rect2D rect
Sharpness Rect.
Definition peak_ipl_sharpness.hpp:133
2D size of an image.
Definition peak_ipl_simple_types.hpp:218