IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
peak_icv_hotpixel_correction_module.hpp
Go to the documentation of this file.
1
11#pragma once
12
18#include <peak_icv_c/algorithms/preprocessing/peak_icv_hotpixel_correction.h>
19
20namespace peak
21{
22namespace pipeline
23{
24
25namespace detail
26{
27
36{
37public:
44
51
60
67
76
83
91 void SetEnabled(bool enabled) override;
92
100 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
101
109 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
110
130 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
131
152 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
153
165 void Serialize(peak::common::serialization::IArchive& archive) const override;
166
167
183 void Deserialize(const peak::common::serialization::IArchive& archive) override;
184
192 void SetList(const std::vector<peak::common::Point>& hotpixels);
193
201 PEAK_COMMON_NO_DISCARD std::vector<peak::common::Point> GetList() const;
202
210 PEAK_COMMON_NO_DISCARD peak::common::IntervalU GetSensitivityRange() const;
211
238 void Detect(const peak::icv::Image& image, uint32_t sensitivity = 3, float gainFactor = 1.0F);
239
247 void ResetToDefault() override;
248
249private:
250 static constexpr int moduleVersion = 1;
251
252 peak_icv_hotpixel_correction_handle m_handle{};
253 bool m_enabled{ true };
254};
255
256inline const char* HotpixelCorrectionModule::GetType() const
257{
258 return "HotpixelCorrection";
259}
260
262{
264 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Create(&m_handle);
265 });
266}
267
269{
270 if (m_handle != nullptr)
271 {
272 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
273 }
274}
275
277{
278 m_handle = std::exchange(other.m_handle, nullptr);
279 m_enabled = other.m_enabled;
280}
281
283{
284 if (this != &other)
285 {
286 if (m_handle != nullptr)
287 {
289 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
290 });
291 }
292
293 m_handle = std::exchange(other.m_handle, nullptr);
294 m_enabled = other.m_enabled;
295 }
296
297 return *this;
298}
299
301{
302 m_enabled = enabled;
303}
304
306{
307 return m_enabled;
308}
309
311{
312 const auto hotpixels = GetList();
313 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> archivePoints;
314 archivePoints.reserve(hotpixels.size());
315
316 std::transform(std::cbegin(hotpixels), std::cend(hotpixels), std::back_inserter(archivePoints), [&archive](const auto& point) {
317 auto archivePoint = archive.CreateArchive();
318 archivePoint->SetInt("X", point.GetX());
319 archivePoint->SetInt("Y", point.GetY());
320 return archivePoint;
321 });
322 archive.SetArchiveArray("HotpixelList", archivePoints);
323
324 archive.SetInt("Version", moduleVersion);
325 archive.SetBool("Enabled", IsEnabled());
326}
327
329{
330 const auto version = archive.GetInt("Version");
332
333 SetEnabled(archive.GetBool("Enabled"));
334
335 const auto archivePoints = archive.GetArchiveArray("HotpixelList");
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) {
339 return peak::common::Point{ static_cast<int32_t>(archive->GetInt("X")), static_cast<int32_t>(archive->GetInt("Y")) };
340 });
341
342 SetList(list);
343}
344
345inline void HotpixelCorrectionModule::SetList(const std::vector<peak::common::Point>& hotpixels)
346{
347 if (hotpixels.empty())
348 {
350 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ResetList(m_handle);
351 });
352 }
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() };
357 });
358
360 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_SetList(m_handle, cPoints.data(), cPoints.size());
361 });
362}
363
364inline std::vector<peak::common::Point> HotpixelCorrectionModule::GetList() const
365{
366 size_t count = 0;
368 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
369 });
370 if (count == 0)
371 {
372 return {};
373 }
374
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);
378 });
379
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 };
384 });
385
386 return cppList;
387}
388
389inline void HotpixelCorrectionModule::Detect(const peak::icv::Image& image, uint32_t sensitivity, float gainFactor)
390{
391 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(image);
392
394 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Detect(m_handle, inputImageHandle, sensitivity, gainFactor);
395 });
396}
397
398inline void HotpixelCorrectionModule::ResetToDefault()
399{
400 SetList({});
401}
402
403inline peak::icv::Image HotpixelCorrectionModule::Process(const peak::icv::Image& input) const
404{
405 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
406}
407
408inline peak::common::Any HotpixelCorrectionModule::Process(const peak::common::Any& input) const
409{
410 auto needsProcessing = [&] {
411 size_t count{};
413 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
414 });
415 return count > 0;
416 };
417
418 if (!IsEnabled() || !needsProcessing())
419 {
420 return input;
421 }
422
423 const auto& inputImage = input.AnyCast<peak::icv::Image>();
424 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
425
427 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace(m_handle, inputImageHandle);
428 });
429
430 return peak::common::Any{ inputImage };
431}
432
433inline peak::common::IntervalU HotpixelCorrectionModule::GetSensitivityRange() const
434{
435 peak_common_interval_u cRange{};
437 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange(m_handle, &cRange);
438 });
439
440 return peak::common::detail::BackendAccessor<peak::common::IntervalU>::CreateInstance(cRange);
441}
442
443} // namespace detail
444} // namespace pipeline
445} // namespace peak
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.
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).
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)