IDS peak ICV v1.0.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
131
153
165 void Serialize(peak::common::serialization::IArchive& archive) const override;
166
167
182 void Deserialize(const peak::common::serialization::IArchive& archive) override;
183
191 void SetList(const std::vector<peak::common::Point>& hotpixels);
192
200 PEAK_COMMON_NO_DISCARD std::vector<peak::common::Point> GetList() const;
201
210
237 void Detect(const peak::icv::Image& image, uint32_t sensitivity = 3, float gainFactor = 1.0F);
238
244 void ResetToDefault() override;
245
246private:
247 static constexpr int moduleVersion = 1;
248
249 peak_icv_hotpixel_correction_handle m_handle{};
250 bool m_enabled{ true };
251};
252
253inline const char* HotpixelCorrectionModule::GetType() const
254{
255 return "HotpixelCorrection";
256}
257
259{
261 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Create(&m_handle);
262 });
263}
264
266{
267 if (m_handle != nullptr)
268 {
269 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
270 }
271}
272
274{
275 m_handle = std::exchange(other.m_handle, nullptr);
276 m_enabled = other.m_enabled;
277}
278
280{
281 if (this != &other)
282 {
283 if (m_handle != nullptr)
284 {
286 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Destroy(m_handle);
287 });
288 }
289
290 m_handle = std::exchange(other.m_handle, nullptr);
291 m_enabled = other.m_enabled;
292 }
293
294 return *this;
295}
296
298{
299 m_enabled = enabled;
300}
301
303{
304 return m_enabled;
305}
306
308{
309 const auto hotpixels = GetList();
310 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> archivePoints;
311 archivePoints.reserve(hotpixels.size());
312
313 std::transform(std::cbegin(hotpixels), std::cend(hotpixels), std::back_inserter(archivePoints), [&archive](const auto& point) {
314 auto archivePoint = archive.CreateArchive();
315 archivePoint->SetInt("X", point.GetX());
316 archivePoint->SetInt("Y", point.GetY());
317 return archivePoint;
318 });
319 archive.SetArchiveArray("HotpixelList", archivePoints);
320
321 archive.SetInt("Version", moduleVersion);
322 archive.SetBool("Enabled", IsEnabled());
323}
324
326{
327 const auto version = archive.GetInt("Version");
329
330 SetEnabled(archive.GetBool("Enabled"));
331
332 const auto archivePoints = archive.GetArchiveArray("HotpixelList");
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) {
336 return peak::common::Point{ static_cast<int32_t>(archive->GetInt("X")), static_cast<int32_t>(archive->GetInt("Y")) };
337 });
338
339 SetList(list);
340}
341
342inline void HotpixelCorrectionModule::SetList(const std::vector<peak::common::Point>& hotpixels)
343{
344 if (hotpixels.empty())
345 {
347 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ResetList(m_handle);
348 });
349 }
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() };
354 });
355
357 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_SetList(m_handle, cPoints.data(), cPoints.size());
358 });
359}
360
361inline std::vector<peak::common::Point> HotpixelCorrectionModule::GetList() const
362{
363 size_t count = 0;
365 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
366 });
367 if (count == 0)
368 {
369 return {};
370 }
371
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);
375 });
376
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 };
381 });
382
383 return cppList;
384}
385
386inline void HotpixelCorrectionModule::Detect(const peak::icv::Image& image, uint32_t sensitivity, float gainFactor)
387{
388 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(image);
389
391 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_Detect(m_handle, inputImageHandle, sensitivity, gainFactor);
392 });
393}
394
395inline void HotpixelCorrectionModule::ResetToDefault()
396{
397 SetList({});
398}
399
400inline peak::icv::Image HotpixelCorrectionModule::Process(const peak::icv::Image& input) const
401{
402 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
403}
404
405inline peak::common::Any HotpixelCorrectionModule::Process(const peak::common::Any& input) const
406{
407 auto needsProcessing = [&] {
408 size_t count{};
410 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(m_handle, &count);
411 });
412 return count > 0;
413 };
414
415 if (!IsEnabled() || !needsProcessing())
416 {
417 return input;
418 }
419
420 const auto& inputImage = input.AnyCast<peak::icv::Image>();
421 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
422
424 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace(m_handle, inputImageHandle);
425 });
426
427 return peak::common::Any{ inputImage };
428}
429
430inline peak::common::IntervalU HotpixelCorrectionModule::GetSensitivityRange() const
431{
432 peak_common_interval_u cRange{};
434 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange(m_handle, &cRange);
435 });
436
437 return peak::common::detail::BackendAccessor<peak::common::IntervalU>::CreateInstance(cRange);
438}
439
440} // namespace detail
441} // namespace pipeline
442} // 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.
#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)