IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
peak_icv_color_matrix_transformation_module.hpp
Go to the documentation of this file.
1
11#pragma once
12
21
22namespace peak
23{
24namespace pipeline
25{
26namespace features
27{
31} // namespace features
32
33namespace detail
34{
35
50{
51public:
60
67
76
83
92
99
111 void Serialize(peak::common::serialization::IArchive& archive) const override;
112
128 void Deserialize(const peak::common::serialization::IArchive& archive) override;
129
138 void SetEnabled(bool enabled) override;
139
148 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
149
157 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
158
168 void ResetToDefault() override;
169
177 void SetMatrix(const ColorCorrectionMatrix& matrix);
178
186 PEAK_COMMON_NO_DISCARD ColorCorrectionMatrix GetMatrix() const;
187
197 void SetSaturation(float saturation);
198
206 PEAK_COMMON_NO_DISCARD float GetSaturation() const;
207
215 PEAK_COMMON_NO_DISCARD peak::common::IntervalF GetSaturationRange() const;
216
233 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
234
253 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
254
260 void SetAutoFeatureModule(const std::shared_ptr<modules::IAutoFeature>& module);
261
270 PEAK_COMMON_NO_DISCARD ColorCorrectionMatrix GetEffectiveMatrix() const;
271
280
288 PEAK_COMMON_NO_DISCARD ChromaticAdaptionAlgorithm GetChromaticAdaptionAlgorithm() const;
289
297 void SetTargetColorSpace(ColorSpace colorSpace);
298
306 PEAK_COMMON_NO_DISCARD ColorSpace GetTargetColorSpace() const;
307
315 void SetColorTemperature(uint32_t temperature);
316
324 PEAK_COMMON_NO_DISCARD uint32_t GetColorTemperature() const;
325
333 PEAK_COMMON_NO_DISCARD peak::common::RangeU GetColorTemperatureRange() const;
334
340 void ResetColorTemperature() const;
341
349 PEAK_COMMON_NO_DISCARD bool HasColorTemperature() const;
350
358 void SetChromaticAdaptionEnabled(bool enabled);
359
367 PEAK_COMMON_NO_DISCARD bool IsChromaticAdaptionEnabled() const;
368
376 void SetSaturationEnabled(bool enabled);
377
385 PEAK_COMMON_NO_DISCARD bool IsSaturationEnabled() const;
386
394 void SetColorCorrectionEnabled(bool enabled);
395
403 PEAK_COMMON_NO_DISCARD bool IsColorCorrectionEnabled() const;
404
411
412private:
413 void UpdateMatrixInAutoFeatureModule() const;
414
415 static constexpr auto saturationKey = "Saturation";
416 static constexpr auto matrixKey = "ColorCorrection";
417 static constexpr auto chromaticAdaptionKey = "ChromaticAdaption";
418
419 peak_icv_color_matrix_transformation_handle m_handle{};
420
421 std::shared_ptr<modules::IAutoFeature> m_autoFeatureModule;
422};
423
425{
427 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_Create(&m_handle);
428 });
429}
430
432{
433 if (m_handle != nullptr)
434 {
435 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_Destroy(m_handle);
436 }
437}
438
440{
441 m_handle = std::exchange(other.m_handle, nullptr);
442}
443
445{
446 if (this != &other)
447 {
448 if (m_handle != nullptr)
449 {
451 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_Destroy(m_handle);
452 });
453 }
454
455 m_handle = std::exchange(other.m_handle, nullptr);
456 }
457
458 return *this;
459}
460
462{
463 archive.SetInt("Version", 2);
464
465 const auto saturationArchive = archive.CreateArchive();
466 saturationArchive->SetBool("Enabled", IsSaturationEnabled());
467 saturationArchive->SetDouble("Value", GetSaturation());
468 archive.SetArchive(saturationKey, saturationArchive);
469
470 const auto matrixArchive = archive.CreateArchive();
471 matrixArchive->SetBool("Enabled", IsColorCorrectionEnabled());
472
473 const auto colorCorrectionMatrix = GetMatrix();
474 colorCorrectionMatrix.Serialize(*matrixArchive);
475 archive.SetArchive(matrixKey, matrixArchive);
476
477 const auto chromaticAdaption = archive.CreateArchive();
478 chromaticAdaption->SetBool("Enabled", IsChromaticAdaptionEnabled());
479 chromaticAdaption->SetString("Algorithm", ToString(GetChromaticAdaptionAlgorithm()));
480 chromaticAdaption->SetString("TargetColorSpace", ToString(GetTargetColorSpace()));
482 {
483 chromaticAdaption->SetInt("ColorTemperature", GetColorTemperature());
484 }
485 archive.SetArchive(chromaticAdaptionKey, chromaticAdaption);
486}
487
489{
490 const auto version = archive.GetInt("Version");
491
493
494 const auto saturationArchive = archive.GetArchive(saturationKey);
495 const auto matrixArchive = archive.GetArchive(matrixKey);
496
497 SetSaturationEnabled(saturationArchive->GetBool("Enabled"));
498 SetColorCorrectionEnabled(matrixArchive->GetBool("Enabled"));
499
501 matrix.Deserialize(*matrixArchive);
502 SetMatrix(matrix);
503
504 SetSaturation(static_cast<float>(saturationArchive->GetDouble("Value")));
505
506 if (version >= 2)
507 {
508 const auto chromaticAdaptionArchive = archive.GetArchive(chromaticAdaptionKey);
509 if (chromaticAdaptionArchive->HasKey("ColorTemperature"))
510 {
511 SetColorTemperature(static_cast<uint32_t>(chromaticAdaptionArchive->GetInt("ColorTemperature")));
512 }
513 else
514 {
516 }
517 SetTargetColorSpace(ToColorSpace(chromaticAdaptionArchive->GetString("TargetColorSpace")));
518 SetChromaticAdaptionAlgorithm(ToChromaticAdaptionAlgorithm(chromaticAdaptionArchive->GetString("Algorithm")));
519 SetChromaticAdaptionEnabled(chromaticAdaptionArchive->GetBool("Enabled"));
520 }
521 else
522 {
524 }
525}
526
528{
530 SetSaturationEnabled(enabled);
532
533 UpdateMatrixInAutoFeatureModule();
534}
535
540
542{
543 return "ColorMatrixTransformation";
544}
545
547{
549 SetSaturation(1.0F);
550
552
553 UpdateMatrixInAutoFeatureModule();
554}
555
557{
558 ColorCorrectionMatrix colorCorrectionMatrix{ "Matrix", ColorCorrectionMatrix::Identity() };
560 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_GetColorCorrectionMatrix(
561 m_handle, reinterpret_cast<peak_icv_color_correction_matrix*>(&colorCorrectionMatrix.At(0, 0)));
562 });
563
564 return colorCorrectionMatrix;
565}
566
568{
570 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_SetColorCorrectionMatrix(
571 m_handle, *reinterpret_cast<const peak_icv_color_correction_matrix*>(&matrix.At(0, 0)));
572 });
573
575 {
576 UpdateMatrixInAutoFeatureModule();
577 }
578}
579
581{
583 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_SetSaturation(m_handle, saturation);
584 });
586 {
587 UpdateMatrixInAutoFeatureModule();
588 }
589}
590
591PEAK_COMMON_NO_DISCARD inline float ColorMatrixTransformationModule::GetSaturation() const
592{
593 float saturation;
595 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_GetSaturation(m_handle, &saturation);
596 });
597 return saturation;
598}
599
601{
602 peak_common_interval_f intervalF;
604 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_GetSaturationRange(m_handle, &intervalF);
605 });
606
607 return { intervalF.minimum, intervalF.maximum };
608}
609
614
616{
617 auto needsProcessing = [&] {
618 bool value{};
620 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_NeedsProcessing(m_handle, &value);
621 });
622 return value;
623 };
624
625 if (!IsEnabled() || !needsProcessing())
626 {
627 return input;
628 }
629
630 const auto& inputImage = input.AnyCast<peak::icv::Image>();
631
632 const auto pixelFormat = inputImage.GetPixelFormat();
633 const peak::common::PixelFormatInfo info(pixelFormat);
636 if (!isColorImage || info.IsPacked())
637 {
638 return input;
639 }
640
641 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
642
644 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ProcessInplace(m_handle, inputImageHandle);
645 });
646
647 return peak::common::Any{ inputImage };
648}
649
650inline void ColorMatrixTransformationModule::UpdateMatrixInAutoFeatureModule() const
651{
652 if (m_autoFeatureModule != nullptr)
653 {
654 std::array<float, 9> data{};
655
656 const auto matrix = GetEffectiveMatrix();
657 std::copy(matrix.cbegin(), matrix.cend(), data.begin());
658
659 m_autoFeatureModule->SetColorCorrectionMatrix(data);
660 }
661}
662
663inline void ColorMatrixTransformationModule::SetAutoFeatureModule(const std::shared_ptr<modules::IAutoFeature>& module)
664{
665 m_autoFeatureModule = module;
666 UpdateMatrixInAutoFeatureModule();
667}
668
670{
671 ColorCorrectionMatrix matrix{};
673 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_GetEffectiveMatrix(
674 m_handle, reinterpret_cast<peak_icv_color_correction_matrix*>(&matrix.At(0, 0)));
675 });
676 return matrix;
677}
678
680{
682 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_Saturation_SetEnabled(m_handle, enabled);
683 });
684 UpdateMatrixInAutoFeatureModule();
685}
686
688{
690 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ColorCorrection_SetEnabled(m_handle, enabled);
691 });
692 UpdateMatrixInAutoFeatureModule();
693}
694
696{
697 bool enabled;
699 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_Saturation_IsEnabled(m_handle, &enabled);
700 });
701 return enabled;
702}
703
705{
706 bool enabled;
708 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ColorCorrection_IsEnabled(m_handle, &enabled);
709 });
710 return enabled;
711}
712
714{
715 peak_icv_chromatic_adaption_algorithm algorithm;
717 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_GetAlgorithm(m_handle, &algorithm);
718 });
719 return static_cast<ChromaticAdaptionAlgorithm>(algorithm);
720}
721
723{
724 peak_icv_color_space colorSpace;
726 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_GetTargetColorSpace(
727 m_handle, &colorSpace);
728 });
729 return static_cast<ColorSpace>(colorSpace);
730}
731
733{
734 const auto cAlgorithm = static_cast<peak_icv_chromatic_adaption_algorithm>(algorithm);
736 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_SetAlgorithm(m_handle, cAlgorithm);
737 });
738 UpdateMatrixInAutoFeatureModule();
739}
740
742{
743 const auto cColorSpace = static_cast<peak_icv_color_space>(colorSpace);
745 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_SetTargetColorSpace(
746 m_handle, cColorSpace);
747 });
748 UpdateMatrixInAutoFeatureModule();
749}
750
752{
753 peak_common_range_u cRange{};
755 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_GetColorTemperatureRange(
756 m_handle, &cRange);
757 });
758
759 return peak::common::detail::BackendAccessor<peak::common::RangeU>::CreateInstance({ cRange });
760}
761
762inline void ColorMatrixTransformationModule::SetColorTemperature(const uint32_t temperature)
763{
765 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_SetColorTemperature(
766 m_handle, temperature);
767 });
768 UpdateMatrixInAutoFeatureModule();
769}
770
772{
773 bool value;
775 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_HasColorTemperature(
776 m_handle, &value);
777 });
778 return value;
779}
780
782{
783 uint32_t temperature{};
785 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_GetColorTemperature(
786 m_handle, &temperature);
787 });
788 return temperature;
789}
790
792{
794 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_ResetColorTemperature(m_handle);
795 });
796 UpdateMatrixInAutoFeatureModule();
797}
798
800{
802 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_SetEnabled(m_handle, enabled);
803 });
804 UpdateMatrixInAutoFeatureModule();
805}
806
808{
809 bool enabled;
811 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ColorMatrixTransformation_ChromaticAdaption_IsEnabled(m_handle, &enabled);
812 });
813 return enabled;
814}
815
822
823} // namespace detail
824} // namespace pipeline
825} // namespace peak
A type-erased container for any copyable value.
T & AnyCast()
Casts the stored value to the specified type.
Provides information and utility functions for pixel formats.
bool HasChannel(Channel channel) const
Checks whether a specific channel is present in the pixel format.
bool IsPacked() const
Returns whether the pixel format is packed.
Represents a continuous numeric interval with inclusive lower and upper bounds.
Represents a numeric range with defined boundaries and a fixed increment.
Interface for a hierarchical key-value archive system.
virtual std::shared_ptr< IArchive > GetArchive(const std::string &key) const =0
Retrieves a nested archive by key.
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 std::shared_ptr< IArchive > CreateArchive() const =0
Creates a new, empty archive instance.
virtual void SetArchive(const std::string &key, const std::shared_ptr< IArchive > &value)=0
Stores a nested archive object.
constexpr Type & At(std::size_t row, std::size_t col)
Accesses the element at the specified row and column.
For detailed information about the use of ids_peak_icv Image refer to the Image Guide.
peak::common::PixelFormat GetPixelFormat() const
Provides the pixel format of the image.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
Color matrix transformation is an image pipeline module that applies a ColorCorrectionMatrix to an im...
uint32_t GetColorTemperature() const
Returns the currently configured source color temperature in Kelvin.
ColorCorrectionMatrix GetMatrix() const
Gets the current ColorCorrectionMatrix.
void SetChromaticAdaptionEnabled(bool enabled)
Enables or disables the chromatic adaptation feature.
ColorMatrixTransformationModule()
Creates an instance of class ColorMatrixTransformationModule with the default color correction matrix...
ColorCorrectionMatrix GetEffectiveMatrix() const
Returns the final effective matrix calculated by concatenating all enabled transformations (e....
bool IsSaturationEnabled() const
Checks if the saturation adjustment feature is enabled.
const char * GetType() const override
Returns the type of the module for serialization purposes.
void ResetColorTemperature() const
Resets the color temperature to its default, uninitialized state.
void SetColorCorrectionEnabled(bool enabled)
Enables or disables the static color correction matrix feature.
void SetColorTemperature(uint32_t temperature)
Sets the source color temperature in Kelvin to be used for chromatic adaptation.
void ResetChromaticAdaption()
Resets all chromatic adaptation settings (temperature, algorithm, color space) to their default value...
bool IsColorCorrectionEnabled() const
Checks if the static color correction matrix feature is enabled.
void SetTargetColorSpace(ColorSpace colorSpace)
Sets the target color space for the chromatic adaptation transformation.
bool IsChromaticAdaptionEnabled() const
Checks if the chromatic adaptation feature is enabled.
ColorMatrixTransformationModule(const ColorMatrixTransformationModule &other)=delete
Copy constructor for class ColorMatrixTransformation is deleted.
void SetAutoFeatureModule(const std::shared_ptr< modules::IAutoFeature > &module)
Sets the auto feature module that should take the color correction matrix into account for automatic ...
void SetMatrix(const ColorCorrectionMatrix &matrix)
Sets the ColorCorrectionMatrix.
bool HasColorTemperature() const
Checks if a specific color temperature has been explicitly set.
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
Processes the input image and returns a color corrected and/or saturated output image.
void SetEnabled(bool enabled) override
Enables or disables the module. When disabled, Process returns the input image unchanged.
void SetChromaticAdaptionAlgorithm(ChromaticAdaptionAlgorithm algorithm)
Sets the algorithm used to calculate the chromatic adaptation transformation.
ColorMatrixTransformationModule & operator=(const ColorMatrixTransformationModule &other)=delete
Copy assignment for class ColorMatrixTransformation is deleted.
peak::common::IntervalF GetSaturationRange() const
Gets the valid range for saturation.
peak::common::RangeU GetColorTemperatureRange() const
Returns the valid range of values for color temperature.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
void ResetToDefault() override
Resets the ColorCorrectionMatrix to the default, the chromatic adaption color space and algorithm to ...
ChromaticAdaptionAlgorithm GetChromaticAdaptionAlgorithm() const
Returns the current algorithm used for chromatic adaptation.
ColorSpace GetTargetColorSpace() const
Returns the target color space used for chromatic adaptation.
bool IsEnabled() const override
Gets whether this module is currently enabled.
void SetSaturationEnabled(bool enabled)
Enables or disables the saturation adjustment feature.
Adjusts to changes in lighting conditions to maintain consistent color perception despite variations ...
Color correction applies a 3x3 ColorCorrectionMatrix to the image.
Adjusts the saturation of an image by modifying a 3x3 ColorCorrectionMatrix.
Interface for a module used within a pipeline.
ColorSpace
Color spaces supported by the chromatic adaptation feature.
ChromaticAdaptionAlgorithm
Algorithm used for chromatic adaption.
@ Bradford
Bradford adaption algorithm (Default).
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
ColorSpace ToColorSpace(const std::string &colorSpace)
std::string ToString(const DebayerConversionPolicy &policy)
void ValidateVersion(int64_t version, const std::string &moduleName)
ChromaticAdaptionAlgorithm ToChromaticAdaptionAlgorithm(const std::string &algorithm)