IDSpeakIPL  v1.8.0
peak_ipl_hotpixel_correction.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
14 
15 #include <cstdint>
16 #include <vector>
17 
18 namespace peak
19 {
20 namespace ipl
21 {
22 
23 class Image;
24 struct Point2D;
25 
26 
27 
37 class HotpixelCorrection final
38 {
39 public:
46  enum class SensitivityLevel
47  {
48  Invalid,
54  };
55 
63 
71 
84 
97 
106  HotpixelCorrection(HotpixelCorrection&& other) noexcept;
107 
117 
128 
139 
149  void SetGainFactorPercent(uint32_t gainFactorPercent = 100);
150 
160  PEAK_IPL_NO_DISCARD uint32_t GainFactorPercent() const;
161 
177  PEAK_IPL_NO_DISCARD std::vector<Point2D> Detect(const Image& inputImage) const;
178 
198  PEAK_IPL_NO_DISCARD Image Correct(const Image& inputImage, const std::vector<Point2D>& hotpixels) const;
199 
218  Image& CorrectInPlace(Image& inputImage, const std::vector<Point2D>& hotpixels) const;
219 
238  PEAK_IPL_NO_DISCARD Image CorrectAdaptive(const Image& inputImage);
239 
256  Image& CorrectAdaptiveInPlace(Image& inputImage);
257 
258 private:
260 };
261 
262 } /* namespace ipl */
263 } /* namespace peak */
264 
266 
267 namespace peak
268 {
269 namespace ipl
270 {
271 
273 {
275  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_AdaptiveHotpixelCorrector_Construct(&m_backendHandle); });
276 
277  // make sure default params are set
278  SetSensitivity();
280 }
281 
283 {
284  if (m_backendHandle)
285  {
287  }
288 }
289 
291 {
292  if (other.m_backendHandle)
293  {
295  }
296 
297  m_backendHandle = other.m_backendHandle;
298 }
299 
301 {
302  if (this != &other)
303  {
304  if (m_backendHandle)
305  {
307  }
308 
309  if (other.m_backendHandle)
310  {
312  [&] { return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_AdaptiveHotpixelCorrector_Acquire(other.m_backendHandle); });
313  }
314  }
315 
316  m_backendHandle = other.m_backendHandle;
317 
318  return *this;
319 }
320 
322 {
323  *this = std::move(other);
324 }
325 
327 {
328  if (this != &other)
329  {
331  m_backendHandle = other.m_backendHandle;
332  other.m_backendHandle = nullptr;
333  }
334 
335  return *this;
336 }
337 
339 {
342  m_backendHandle, static_cast<PEAK_IPL_HOTPIXELCORRECTION_SENSITIVITY>(sensitivityLevel));
343  });
344 }
345 
347 {
351  m_backendHandle, &sensitivityLevel);
352  });
353 
354  return static_cast<SensitivityLevel>(sensitivityLevel);
355 }
356 
357 inline void HotpixelCorrection::SetGainFactorPercent(uint32_t gainFactorPercent)
358 {
361  m_backendHandle, gainFactorPercent);
362  });
363 }
364 
366 {
367  uint32_t gainFactorPercent;
370  m_backendHandle, &gainFactorPercent);
371  });
372 
373  return gainFactorPercent;
374 }
375 
376 inline std::vector<Point2D> HotpixelCorrection::Detect(const Image& inputImage) const
377 {
380  m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage));
381  });
382 
383  size_t size = 0;
385  return PEAK_IPL_C_ABI_PREFIX PEAK_IPL_AdaptiveHotpixelCorrector_GetHotpixels(m_backendHandle, nullptr, &size);
386  });
387  std::vector<Point2D> hotpixels(size);
390  m_backendHandle, reinterpret_cast<PEAK_IPL_POINT_2D*>(hotpixels.data()), &size);
391  });
392 
393  return hotpixels;
394 }
395 
396 inline Image HotpixelCorrection::Correct(const Image& inputImage, const std::vector<Point2D>& hotpixels) const
397 {
398  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
401  ImageBackendAccessor::BackendHandle(inputImage),
402  reinterpret_cast<const PEAK_IPL_POINT_2D*>(hotpixels.data()), hotpixels.size(), &outputImageHandle);
403  });
404 
405  return ImageBackendAccessor::CreateImage(outputImageHandle);
406 }
407 
408 inline Image& HotpixelCorrection::CorrectInPlace(Image& inputImage, const std::vector<Point2D>& hotpixels) const
409 {
412  ImageBackendAccessor::BackendHandle(inputImage),
413  reinterpret_cast<const PEAK_IPL_POINT_2D*>(hotpixels.data()), hotpixels.size());
414  });
415 
416  return inputImage;
417 }
418 
420 {
421  PEAK_IPL_IMAGE_HANDLE outputImageHandle = nullptr;
424  m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage), &outputImageHandle);
425  });
426 
427  return ImageBackendAccessor::CreateImage(outputImageHandle);
428 }
429 
431 {
434  m_backendHandle, ImageBackendAccessor::BackendHandle(inputImage));
435  });
436 
437  return inputImage;
438 }
439 
440 
441 } /* namespace ipl */
442 } /* namespace peak */
#define PEAK_IPL_NO_DISCARD
Definition: peak_ipl_backend.h:26
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_Detect(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle)
Detects hotpixels in the given image.
PEAK_IPL_NO_DISCARD Image CorrectAdaptive(const Image &inputImage)
Corrects the given image adaptively.
Definition: peak_ipl_hotpixel_correction.hpp:419
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_GetSensitivity(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, PEAK_IPL_HOTPIXELCORRECTION_SENSITIVITY *sensitivityLevel)
Queries the given adaptive hotpixel corrector algorithm&#39;s current sensitivity.
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_SetGainFactorPercent(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, uint32_t gainFactorPercent)
Sets the given adaptive hotpixel corrector algorithm&#39;s gain factor in percent.
#define PEAK_IPL_C_ABI_PREFIX
Definition: peak_ipl_dll_defines.h:16
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_GetHotpixels(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, struct PEAK_IPL_POINT_2D *hotpixels, size_t *hotpixelsSize)
Queries previously detected hotpixels.
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_CorrectInPlace(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle, const struct PEAK_IPL_POINT_2D *hotpixels, size_t hotpixelsSize)
Corrects the given hotpixels in place of the given image.
Image & CorrectInPlace(Image &inputImage, const std::vector< Point2D > &hotpixels) const
Corrects the given hotpixels inplace in the given image.
Definition: peak_ipl_hotpixel_correction.hpp:408
The "peak::ipl" namespace contains the whole image processing library.
Definition: peak_ipl_binning.hpp:22
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition: peak_ipl_exception.hpp:182
Algorithm for (adaptive) hotpixel detection and correction.
Definition: peak_ipl_hotpixel_correction.hpp:37
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_CorrectAdaptive(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Detects and corrects hotpixels in the given image.
~HotpixelCorrection()
Destructor for the HotpixelCorrection instance.
Definition: peak_ipl_hotpixel_correction.hpp:282
PEAK_IPL_NO_DISCARD Image Correct(const Image &inputImage, const std::vector< Point2D > &hotpixels) const
Corrects the given hotpixels in the given image.
Definition: peak_ipl_hotpixel_correction.hpp:396
Stores the pixel format, width and height of an image and the pointer to the image buffer...
Definition: peak_ipl_image.hpp:39
PEAK_IPL_NO_DISCARD SensitivityLevel Sensitivity() const
Returns the current sensitivity.
Definition: peak_ipl_hotpixel_correction.hpp:346
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_Acquire(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle)
Increase the reference count of an adaptive hotpixel corrector.
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_Construct(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE *adaptiveHotpixelCorrectorHandle)
Creates an adaptive hotpixel corrector algorithm.
SensitivityLevel
SensitivityLevel parameter for the HotpixelCorrection algorithm.
Definition: peak_ipl_hotpixel_correction.hpp:46
HotpixelCorrection & operator=(const HotpixelCorrection &other)
Copy assigment for HotpixelCorrection instance.
Definition: peak_ipl_hotpixel_correction.hpp:300
struct PEAK_IPL_IMAGE * PEAK_IPL_IMAGE_HANDLE
Definition: peak_ipl_backend.h:354
PEAK_IPL_NO_DISCARD uint32_t GainFactorPercent() const
Returns the current gain factor in percent.
Definition: peak_ipl_hotpixel_correction.hpp:365
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_GetGainFactorPercent(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, uint32_t *gainFactorPercent)
Queries the given adaptive hotpixel corrector algorithm&#39;s current gain factor in percent.
void SetSensitivity(SensitivityLevel sensitivityLevel=SensitivityLevel::SensitivityLevel3)
Sets the sensitivity of the hotpixel detection.
Definition: peak_ipl_hotpixel_correction.hpp:338
int32_t PEAK_IPL_HOTPIXELCORRECTION_SENSITIVITY
Definition: peak_ipl_backend.h:214
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_Correct(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle, const struct PEAK_IPL_POINT_2D *hotpixels, size_t hotpixelsSize, PEAK_IPL_IMAGE_HANDLE *outputImageHandle)
Corrects the given hotpixels in the given image.
Image & CorrectAdaptiveInPlace(Image &inputImage)
Corrects the given image inplace adaptively.
Definition: peak_ipl_hotpixel_correction.hpp:430
PEAK_IPL_NO_DISCARD std::vector< Point2D > Detect(const Image &inputImage) const
Detects hotpixels in the given image.
Definition: peak_ipl_hotpixel_correction.hpp:376
HotpixelCorrection()
Constructor for a new HotpixelCorrection instance.
Definition: peak_ipl_hotpixel_correction.hpp:272
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_CorrectAdaptiveInPlace(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, PEAK_IPL_IMAGE_HANDLE inputImageHandle)
Detects and corrects hotpixels in place within the given image.
void SetGainFactorPercent(uint32_t gainFactorPercent=100)
Sets the gain factor in percent.
Definition: peak_ipl_hotpixel_correction.hpp:357
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_SetSensitivity(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle, PEAK_IPL_HOTPIXELCORRECTION_SENSITIVITY sensitivityLevel)
Sets the given adaptive hotpixel corrector algorithm&#39;s sensitivity.
PEAK_IPL_C_API PEAK_IPL_AdaptiveHotpixelCorrector_Destruct(PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE adaptiveHotpixelCorrectorHandle)
Destroys the adaptive hotpixel corrector algorithm associated with the given handle.
struct PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR * PEAK_IPL_ADAPTIVE_HOTPIXEL_CORRECTOR_HANDLE
Definition: peak_ipl_backend.h:330