18#include <peak_icv_c/algorithms/preprocessing/peak_icv_hotpixel_correction.h>
191 void SetList(
const std::vector<peak::common::Point>& hotpixels);
247 static constexpr int moduleVersion = 1;
249 peak_icv_hotpixel_correction_handle m_handle{};
250 bool m_enabled{
true };
255 return "HotpixelCorrection";
261 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Create(&m_handle);
267 if (m_handle !=
nullptr)
269 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
275 m_handle = std::exchange(other.m_handle,
nullptr);
276 m_enabled = other.m_enabled;
283 if (m_handle !=
nullptr)
286 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
290 m_handle = std::exchange(other.m_handle,
nullptr);
291 m_enabled = other.m_enabled;
309 const auto hotpixels =
GetList();
310 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> archivePoints;
311 archivePoints.reserve(hotpixels.size());
313 std::transform(std::cbegin(hotpixels), std::cend(hotpixels), std::back_inserter(archivePoints), [&archive](
const auto& point) {
315 archivePoint->SetInt(
"X", point.GetX());
316 archivePoint->SetInt(
"Y", point.GetY());
321 archive.
SetInt(
"Version", moduleVersion);
327 const auto version = archive.
GetInt(
"Version");
333 std::vector<peak::common::Point> list;
334 list.reserve(archivePoints.size());
335 std::transform(std::cbegin(archivePoints), std::cend(archivePoints), std::back_inserter(list), [](
const auto& archive) {
344 if (hotpixels.empty())
347 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ResetList(m_handle);
350 std::vector<peak_common_point> cPoints;
351 cPoints.reserve(hotpixels.size());
352 std::transform(hotpixels.cbegin(), hotpixels.cend(), std::back_inserter(cPoints), [](
const peak::common::Point& cppPoint) {
353 return peak_common_point{ cppPoint.GetX(), cppPoint.GetY() };
357 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_SetList(m_handle, cPoints.data(), cPoints.size());
361inline std::vector<peak::common::Point> HotpixelCorrectionModule::GetList()
const
365 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
372 std::vector<peak_common_point> cList(count);
374 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList(m_handle, cList.data(), count);
377 std::vector<peak::common::Point> cppList{};
378 cppList.reserve(count);
379 std::transform(cList.begin(), cList.end(), std::back_inserter(cppList), [](
const peak_common_point& cPoint) {
380 return peak::common::Point{ cPoint.x, cPoint.y };
386inline void HotpixelCorrectionModule::Detect(
const peak::icv::Image& image, uint32_t sensitivity,
float gainFactor)
388 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(image);
391 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Detect(m_handle, inputImageHandle, sensitivity, gainFactor);
395inline void HotpixelCorrectionModule::ResetToDefault()
407 auto needsProcessing = [&] {
410 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
415 if (!IsEnabled() || !needsProcessing())
421 auto*
const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
424 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace(m_handle, inputImageHandle);
432 peak_common_interval_u cRange{};
434 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange(m_handle, &cRange);
437 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
Sets the enabled state of this 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
Checks if the module is currently enabled.
Interface for a module used within a pipeline.
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)