IDS peak IPL v1.17.2
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;
43class Sharpness final
44{
45public:
52 Sharpness();
53
60 ~Sharpness();
61
73 Sharpness(const Sharpness& other);
74
86 Sharpness& operator=(const Sharpness& other);
87
96 Sharpness(Sharpness&& other) noexcept;
97
106 Sharpness& operator=(Sharpness&& other) noexcept;
107
116
120 enum class SharpnessROIWeight : uint16_t
121 {
122 Weak = 0x0021,
123 Medium = 0x0042,
124 Strong = 0x0063
125 };
126
139
140 using SharpnessROIList = std::vector<SharpnessROI>;
141
155 inline double Measure(const Image& image);
156
165 PEAK_IPL_NO_DISCARD inline bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const;
166
173 PEAK_IPL_NO_DISCARD inline std::vector<PixelFormatName> SupportedPixelFormats() const;
174
180 inline void SetAlgorithm(SharpnessAlgorithm algorithm);
181
189
197
204 inline void SetROIs(const SharpnessROIList& rois);
205
212 inline void SetROI(const SharpnessROI& roi);
213
220 inline void SetROI(const Rect2D& roi);
221
229
230private:
231 PEAK_IPL_SHARPNESS_HANDLE m_backendHandle{};
232};
233
238
240{
241 if (m_backendHandle)
242 {
244 }
245}
246
247inline Sharpness::Sharpness(const Sharpness& other)
248{
249 if (other.m_backendHandle)
250 {
252 }
253
254 m_backendHandle = other.m_backendHandle;
255}
256
258{
259 if (this != &other)
260 {
261 if (m_backendHandle)
262 {
264 }
265
266 if (other.m_backendHandle)
267 {
269 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageSharpness_Acquire(other.m_backendHandle); });
270 }
271 }
272
273 m_backendHandle = other.m_backendHandle;
274
275 return *this;
276}
277
278inline Sharpness::Sharpness(Sharpness&& other) noexcept
279{
280 *this = std::move(other);
281}
282
283inline Sharpness& Sharpness::operator=(Sharpness&& other) noexcept
284{
285 if (this != &other)
286 {
287 if (m_backendHandle != nullptr)
288 {
290 }
291
292 m_backendHandle = other.m_backendHandle;
293 other.m_backendHandle = nullptr;
294 }
295
296 return *this;
297}
298
299inline double Sharpness::Measure(const Image& image)
300{
301 double calculated_value;
302
305 m_backendHandle, ImageBackendAccessor::BackendHandle(image), &calculated_value);
306 });
307
308 return calculated_value;
309}
310
311inline bool Sharpness::IsPixelFormatSupported(PixelFormatName pixelFormatName) const
312{
313 PEAK_IPL_BOOL8 isPixelFormatSupported = 0;
314
317 static_cast<PEAK_IPL_PIXEL_FORMAT>(pixelFormatName),
318 reinterpret_cast<PEAK_IPL_BOOL8*>(&isPixelFormatSupported));
319 });
320
321 return isPixelFormatSupported > 0;
322}
323
324inline std::vector<PixelFormatName> Sharpness::SupportedPixelFormats() const
325{
326 size_t sizeOfData{};
329 m_backendHandle, nullptr, &sizeOfData);
330 });
331
332 std::vector<PixelFormatName> formats(sizeOfData);
335 m_backendHandle, reinterpret_cast<PEAK_IPL_PIXEL_FORMAT*>(formats.data()), &sizeOfData);
336 });
337
338 return formats;
339}
340
342{
345 m_backendHandle, static_cast<PEAK_IPL_SHARPNESS_ALGORITHM>(algorithm));
346 });
347}
348
350{
351 SharpnessAlgorithm algorithm;
352
355 m_backendHandle, reinterpret_cast<PEAK_IPL_SHARPNESS_ALGORITHM*>(&algorithm));
356 });
357
358 return algorithm;
359}
360
362{
363 PEAK_IPL_SIZE_2D size{};
364
366 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageSharpness_GetROIMinimumSize(m_backendHandle, &size); });
367
368 return Size2D{ size.width, size.height };
369}
370
371inline void Sharpness::SetROIs(const SharpnessROIList& rois)
372{
374 std::vector<PEAK_IPL_SHARPNESS_ROI> sharpness_rois{};
375
376 std::transform(std::cbegin(rois), std::cend(rois), std::back_inserter(sharpness_rois), [](const auto roi) {
377 return PEAK_IPL_SHARPNESS_ROI{ PEAK_IPL_RECT_2D{ { roi.rect.topLeft().x, roi.rect.topLeft().y },
378 { roi.rect.size().width, roi.rect.size().height } },
379 roi.xSamplingInterval, roi.ySamplingInterval,
380 static_cast<std::underlying_type_t<SharpnessROIWeight>>(roi.weight) };
381 });
382
384 m_backendHandle, sharpness_rois.data(), sharpness_rois.size());
385 });
386}
387
388inline void Sharpness::SetROI(const SharpnessROI& roi)
389{
390 SharpnessROIList rois{ roi };
391 SetROIs(rois);
392}
393
394inline void Sharpness::SetROI(const Rect2D& roi)
395{
396 SharpnessROI sharpnessRoi{ roi, 1, 1, SharpnessROIWeight::Medium };
397 SetROI(sharpnessRoi);
398}
399
401{
402 size_t roiListSize{};
404 [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_ImageSharpness_GetROIs(m_backendHandle, nullptr, &roiListSize); });
405
406 std::vector<PEAK_IPL_SHARPNESS_ROI> sharpness_rois(roiListSize);
409 m_backendHandle, sharpness_rois.data(), &roiListSize);
410 });
411
412 SharpnessROIList rois{};
413
414 std::transform(
415 std::cbegin(sharpness_rois), std::cend(sharpness_rois), std::back_inserter(rois), [](const auto roi) {
416 return SharpnessROI{ Rect2D{ roi.rect.position.x, roi.rect.position.y, roi.rect.size.width,
417 roi.rect.size.height },
418 roi.xSamplingInterval, roi.ySamplingInterval, static_cast<SharpnessROIWeight>(roi.weight) };
419 });
420
421 return rois;
422}
423
425{
426 return lhs.rect == rhs.rect && lhs.weight == rhs.weight && lhs.xSamplingInterval == rhs.xSamplingInterval
428}
429
431{
432 return !(lhs == rhs);
433}
434
435} /* namespace ipl */
436} /* namespace peak */
Stores the pixel format, width and height of an image and the pointer to the image buffer.
Definition peak_ipl_image.hpp:47
Rectangle type.
Definition peak_ipl_rect.hpp:33
Sharpness()
Constructor for a new Sharpness instance.
Definition peak_ipl_sharpness.hpp:234
Sharpness & operator=(const Sharpness &other)
Copy assigment for Sharpness instance.
Definition peak_ipl_sharpness.hpp:257
void SetROIs(const SharpnessROIList &rois)
Sets the region of interests in which the sharpness is measured.
Definition peak_ipl_sharpness.hpp:371
Size2D ROIMinSize() const
Gets the minimum size of a ROI, in which the sharpness is measured.
Definition peak_ipl_sharpness.hpp:361
void SetROI(const SharpnessROI &roi)
Set ROI in which the sharpness is measured.
Definition peak_ipl_sharpness.hpp:388
SharpnessAlgorithm
Measure Algorithms.
Definition peak_ipl_sharpness.hpp:110
@ HistogramVariance
statistics-based sharpness algorithm
Definition peak_ipl_sharpness.hpp:113
@ Tenengrad
contrast-based sharpness algorithm (convolution)
Definition peak_ipl_sharpness.hpp:111
@ Sobel
contrast-based sharpness algorithm (convolution)
Definition peak_ipl_sharpness.hpp:114
@ MeanScore
contrast-based sharpness algorithm (mean value)
Definition peak_ipl_sharpness.hpp:112
SharpnessROIList ROIs() const
Gets ROIs in which the sharpness is measured.
Definition peak_ipl_sharpness.hpp:400
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:299
SharpnessROIWeight
Definition peak_ipl_sharpness.hpp:121
@ Weak
Weak use of roi for the measurement.
Definition peak_ipl_sharpness.hpp:122
@ Medium
Normal use of roi for the measurement.
Definition peak_ipl_sharpness.hpp:123
@ Strong
Strong use of roi for the measurement.
Definition peak_ipl_sharpness.hpp:124
std::vector< SharpnessROI > SharpnessROIList
Definition peak_ipl_sharpness.hpp:140
bool IsPixelFormatSupported(PixelFormatName pixelFormatName) const
Checks if the given pixel format can be used for sharpness measurement.
Definition peak_ipl_sharpness.hpp:311
~Sharpness()
Destructor for the Sharpness instance.
Definition peak_ipl_sharpness.hpp:239
void SetAlgorithm(SharpnessAlgorithm algorithm)
Sets the algorithm used for measurement calculation.
Definition peak_ipl_sharpness.hpp:341
SharpnessAlgorithm Algorithm() const
Returns the used algorithm for the sharpness measurement.
Definition peak_ipl_sharpness.hpp:349
std::vector< PixelFormatName > SupportedPixelFormats() const
Returns a list of supported pixel formats which can be used for sharpness measurement.
Definition peak_ipl_sharpness.hpp:324
PixelFormatName
Enum holding the possible pixel format names.
Definition peak_ipl_simple_types.hpp:43
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:430
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:289
bool operator==(const Sharpness::SharpnessROI &lhs, const Sharpness::SharpnessROI &rhs)
Definition peak_ipl_sharpness.hpp:424
#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
size_t height
Definition peak_ipl_backend.h:267
size_t width
Definition peak_ipl_backend.h:266
Definition peak_ipl_sharpness.hpp:128
uint8_t ySamplingInterval
vertical sampling interval
Definition peak_ipl_sharpness.hpp:136
SharpnessROIWeight weight
weight for the roi
Definition peak_ipl_sharpness.hpp:137
uint8_t xSamplingInterval
horizontal sampling interval
Definition peak_ipl_sharpness.hpp:135
SharpnessROI(Rect2D rect, uint8_t xSamplingInterval, uint8_t ySamplingInterval, SharpnessROIWeight weight)
Definition peak_ipl_sharpness.hpp:131
Rect2D rect
Sharpness Rect.
Definition peak_ipl_sharpness.hpp:134
2D size of an image.
Definition peak_ipl_simple_types.hpp:225