18#include <peak_icv_c/algorithms/preprocessing/peak_icv_hotpixel_correction.h>
100 PEAK_COMMON_NO_DISCARD
bool IsEnabled()
const override;
109 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override;
192 void SetList(
const std::vector<peak::common::Point>& hotpixels);
201 PEAK_COMMON_NO_DISCARD std::vector<peak::common::Point>
GetList()
const;
250 static constexpr int moduleVersion = 1;
252 peak_icv_hotpixel_correction_handle m_handle{};
253 bool m_enabled{
true };
258 return "HotpixelCorrection";
264 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Create(&m_handle);
270 if (m_handle !=
nullptr)
272 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
278 m_handle = std::exchange(other.m_handle,
nullptr);
279 m_enabled = other.m_enabled;
286 if (m_handle !=
nullptr)
289 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
293 m_handle = std::exchange(other.m_handle,
nullptr);
294 m_enabled = other.m_enabled;
312 const auto hotpixels =
GetList();
313 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> archivePoints;
314 archivePoints.reserve(hotpixels.size());
316 std::transform(std::cbegin(hotpixels), std::cend(hotpixels), std::back_inserter(archivePoints), [&archive](
const auto& point) {
318 archivePoint->SetInt(
"X", point.GetX());
319 archivePoint->SetInt(
"Y", point.GetY());
324 archive.
SetInt(
"Version", moduleVersion);
330 const auto version = archive.
GetInt(
"Version");
336 std::vector<peak::common::Point> list;
337 list.reserve(archivePoints.size());
338 std::transform(std::cbegin(archivePoints), std::cend(archivePoints), std::back_inserter(list), [](
const auto& archive) {
347 if (hotpixels.empty())
350 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ResetList(m_handle);
353 std::vector<peak_common_point> cPoints;
354 cPoints.reserve(hotpixels.size());
355 std::transform(hotpixels.cbegin(), hotpixels.cend(), std::back_inserter(cPoints), [](
const peak::common::Point& cppPoint) {
356 return peak_common_point{ cppPoint.GetX(), cppPoint.GetY() };
360 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_SetList(m_handle, cPoints.data(), cPoints.size());
364inline std::vector<peak::common::Point> HotpixelCorrectionModule::GetList()
const
368 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
375 std::vector<peak_common_point> cList(count);
377 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList(m_handle, cList.data(), count);
380 std::vector<peak::common::Point> cppList{};
381 cppList.reserve(count);
382 std::transform(cList.begin(), cList.end(), std::back_inserter(cppList), [](
const peak_common_point& cPoint) {
383 return peak::common::Point{ cPoint.x, cPoint.y };
389inline void HotpixelCorrectionModule::Detect(
const peak::icv::Image& image, uint32_t sensitivity,
float gainFactor)
391 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(image);
394 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Detect(m_handle, inputImageHandle, sensitivity, gainFactor);
398inline void HotpixelCorrectionModule::ResetToDefault()
410 auto needsProcessing = [&] {
413 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
418 if (!IsEnabled() || !needsProcessing())
424 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
427 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace(m_handle, inputImageHandle);
435 peak_common_interval_u cRange{};
437 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange(m_handle, &cRange);
440 return peak::common::detail::BackendAccessor<peak::common::IntervalU>::CreateInstance(cRange);
A type-erased container for any copyable value.
T & AnyCast()
Casts the stored value to the specified type.
Represents a continuous numeric interval with inclusive lower and upper bounds.
Interface for a hierarchical key-value archive system.
virtual std::vector< std::shared_ptr< IArchive > > GetArchiveArray(const std::string &key) const =0
Retrieves an array of nested archives by key.
virtual void SetBool(const std::string &key, bool value)=0
Stores a boolean value.
virtual void SetArchiveArray(const std::string &key, const std::vector< std::shared_ptr< IArchive > > &value)=0
Stores an array of nested archives.
virtual void SetInt(const std::string &key, int64_t value)=0
Stores a 64-bit signed integer.
virtual int64_t GetInt(const std::string &key) const =0
Retrieves a 64-bit signed integer by key.
virtual bool GetBool(const std::string &key) const =0
Retrieves a boolean value by key.
virtual std::shared_ptr< IArchive > CreateArchive() const =0
Creates a new, empty archive instance.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
Hotpixel correction is an image pipeline module for detecting and correcting hot pixels in camera ima...
HotpixelCorrectionModule & operator=(const HotpixelCorrectionModule &other)=delete
Copy assignment for class HotpixelCorrectionModule is deleted.
HotpixelCorrectionModule(const HotpixelCorrectionModule &other)=delete
Copy constructor for class HotpixelCorrectionModule is deleted.
const char * GetType() const override
Returns the type of the module for serialization purposes.
std::vector< peak::common::Point > GetList() const
Retrieves the current list of known hot pixels.
~HotpixelCorrectionModule() override
void Detect(const peak::icv::Image &image, uint32_t sensitivity=3, float gainFactor=1.0F)
Performs immediate hot pixel detection on the given image.
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the object's internal state into the provided archive.
peak::icv::Image Process(const peak::icv::Image &input) const
Applies hot pixel correction to the input image in place and returns a reference to the modified imag...
void SetList(const std::vector< peak::common::Point > &hotpixels)
Sets the list of known hot pixels.
void SetEnabled(bool enabled) override
Enables or disables the module.
peak::common::IntervalU GetSensitivityRange() const
Returns the valid range of sensitivities.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
HotpixelCorrectionModule()
Creates a HotpixelCorrectionModule module with default settings (no correction).
void ResetToDefault() override
Clears the hot pixel list.
bool IsEnabled() const override
Gets whether this module is currently enabled.
Interface for a module used within a pipeline.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)