IDS peak ICV v1.1.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
245 void ResetToDefault() override;
246
247private:
248 static constexpr int moduleVersion = 1;
249
250 peak_icv_hotpixel_correction_handle m_handle{};
251 bool m_enabled{ true };
252};
253
254inline const char* HotpixelCorrectionModule::GetType() const
255{
256 return "HotpixelCorrection";
257}
258
260{
262 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Create(&m_handle);
263 });
264}
265
267{
268 if (m_handle != nullptr)
269 {
270 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
271 }
272}
273
275{
276 m_handle = std::exchange(other.m_handle, nullptr);
277 m_enabled = other.m_enabled;
278}
279
281{
282 if (this != &other)
283 {
284 if (m_handle != nullptr)
285 {
287 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
288 });
289 }
290
291 m_handle = std::exchange(other.m_handle, nullptr);
292 m_enabled = other.m_enabled;
293 }
294
295 return *this;
296}
297
299{
300 m_enabled = enabled;
301}
302
304{
305 return m_enabled;
306}
307
309{
310 const auto hotpixels = GetList();
311 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> archivePoints;
312 archivePoints.reserve(hotpixels.size());
313
314 std::transform(std::cbegin(hotpixels), std::cend(hotpixels), std::back_inserter(archivePoints), [&archive](const auto& point) {
315 auto archivePoint = archive.CreateArchive();
316 archivePoint->SetInt("X", point.GetX());
317 archivePoint->SetInt("Y", point.GetY());
318 return archivePoint;
319 });
320 archive.SetArchiveArray("HotpixelList", archivePoints);
321
322 archive.SetInt("Version", moduleVersion);
323 archive.SetBool("Enabled", IsEnabled());
324}
325
327{
328 const auto version = archive.GetInt("Version");
330
331 SetEnabled(archive.GetBool("Enabled"));
332
333 const auto archivePoints = archive.GetArchiveArray("HotpixelList");
334 std::vector<peak::common::Point> list;
335 list.reserve(archivePoints.size());
336 std::transform(std::cbegin(archivePoints), std::cend(archivePoints), std::back_inserter(list), [](const auto& archive) {
337 return peak::common::Point{ static_cast<int32_t>(archive->GetInt("X")), static_cast<int32_t>(archive->GetInt("Y")) };
338 });
339
340 SetList(list);
341}
342
343inline void HotpixelCorrectionModule::SetList(const std::vector<peak::common::Point>& hotpixels)
344{
345 if (hotpixels.empty())
346 {
348 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ResetList(m_handle);
349 });
350 }
351 std::vector<peak_common_point> cPoints;
352 cPoints.reserve(hotpixels.size());
353 std::transform(hotpixels.cbegin(), hotpixels.cend(), std::back_inserter(cPoints), [](const peak::common::Point& cppPoint) {
354 return peak_common_point{ cppPoint.GetX(), cppPoint.GetY() };
355 });
356
358 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_SetList(m_handle, cPoints.data(), cPoints.size());
359 });
360}
361
362inline std::vector<peak::common::Point> HotpixelCorrectionModule::GetList() const
363{
364 size_t count = 0;
366 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
367 });
368 if (count == 0)
369 {
370 return {};
371 }
372
373 std::vector<peak_common_point> cList(count);
375 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList(m_handle, cList.data(), count);
376 });
377
378 std::vector<peak::common::Point> cppList{};
379 cppList.reserve(count);
380 std::transform(cList.begin(), cList.end(), std::back_inserter(cppList), [](const peak_common_point& cPoint) {
381 return peak::common::Point{ cPoint.x, cPoint.y };
382 });
383
384 return cppList;
385}
386
387inline void HotpixelCorrectionModule::Detect(const peak::icv::Image& image, uint32_t sensitivity, float gainFactor)
388{
389 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(image);
390
392 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Detect(m_handle, inputImageHandle, sensitivity, gainFactor);
393 });
394}
395
396inline void HotpixelCorrectionModule::ResetToDefault()
397{
398 SetList({});
399}
400
401inline peak::icv::Image HotpixelCorrectionModule::Process(const peak::icv::Image& input) const
402{
403 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
404}
405
406inline peak::common::Any HotpixelCorrectionModule::Process(const peak::common::Any& input) const
407{
408 auto needsProcessing = [&] {
409 size_t count{};
411 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
412 });
413 return count > 0;
414 };
415
416 if (!IsEnabled() || !needsProcessing())
417 {
418 return input;
419 }
420
421 const auto& inputImage = input.AnyCast<peak::icv::Image>();
422 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
423
425 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace(m_handle, inputImageHandle);
426 });
427
428 return peak::common::Any{ inputImage };
429}
430
431inline peak::common::IntervalU HotpixelCorrectionModule::GetSensitivityRange() const
432{
433 peak_common_interval_u cRange{};
435 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange(m_handle, &cRange);
436 });
437
438 return peak::common::detail::BackendAccessor<peak::common::IntervalU>::CreateInstance(cRange);
439}
440
441} // namespace detail
442} // namespace pipeline
443} // 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
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).
bool IsEnabled() const override
Checks if the 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)