IDS peak AFL v2.0.1
Loading...
Searching...
No Matches
peak_afl_sharpness_algorithm.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <peak_afl/peak_afl.hpp>
15
17
18#include <memory>
19
20namespace peak
21{
22namespace pipeline
23{
24namespace modules
25{
26namespace autofeature
27{
39{
46 Auto PEAK_AFL_DEPRECATED_ENUM_ATTR,
55};
56
70{
71 // clang-format off
72 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
73 if (algorithm == FocusSharpnessAlgorithm::Auto)
74 {
75 return "Auto";
76 }
77 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
78 // clang-format on
80 {
81 return "HistogramVariance";
82 }
84 {
85 return "MeanScore";
86 }
87 if (algorithm == FocusSharpnessAlgorithm::Sobel)
88 {
89 return "Sobel";
90 }
92 {
93 return "Tenengrad";
94 }
96 "The given focus sharpness algorithm is unknown!", PEAK_AFL_STATUS_INVALID_PARAMETER);
97}
98
117inline std::ostream& operator<<(std::ostream& os, FocusSharpnessAlgorithm algorithm)
118{
119 return os << ToString(algorithm);
120}
121
122namespace features
123{
124namespace detail
125{
126PEAK_COMMON_NO_DISCARD inline FocusSharpnessAlgorithm ToFocusSharpnessAlgorithm(const std::string& algorithm)
127{
128 if (algorithm == "Auto")
129 {
130 // clang-format off
131 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
133 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
134 // clang-format on
135 }
136 if (algorithm == "Tenengrad")
137 {
139 }
140 if (algorithm == "Sobel")
141 {
143 }
144 if (algorithm == "MeanScore")
145 {
147 }
148 if (algorithm == "HistogramVariance")
149 {
151 }
152
153 throw peak::afl::error::InvalidParameterException(
154 "The given focus sharpness algorithm " + algorithm + " is unknown!", PEAK_AFL_STATUS_INVALID_PARAMETER);
155}
156
158{
159 // clang-format off
160 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
161 switch (algorithm)
162 {
173 }
174 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
175 // clang-format on
176
177 throw peak::afl::error::InternalErrorException("Invalid focus sharpness algorithm!", PEAK_AFL_STATUS_ERROR);
178}
179
181{
182 // clang-format off
183 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
184 switch (algorithm)
185 {
196 }
197 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
198 // clang-format on
199
200 throw peak::afl::error::InternalErrorException("Invalid focus sharpness algorithm!", PEAK_AFL_STATUS_ERROR);
201}
202} // namespace detail
203
233class SharpnessAlgorithm : public IListFeature<FocusSharpnessAlgorithm>
234{
235public:
248 explicit SharpnessAlgorithm(std::shared_ptr<peak::afl::Controller> controller)
249 : m_controller{ std::move(controller) }
250 {}
251
272 void Set(const FocusSharpnessAlgorithm& value) override
273 {
274 m_controller->SetSharpnessAlgorithm(detail::ToCType(value));
275 }
276
295 {
296 return detail::ToFocusSharpnessAlgorithm(m_controller->GetSharpnessAlgorithm());
297 }
298
317 PEAK_COMMON_NO_DISCARD std::vector<FocusSharpnessAlgorithm> GetList() const override
318 {
319 const auto cAlgorithms = m_controller->GetSharpnessAlgorithmList();
320 std::vector<FocusSharpnessAlgorithm> algorithms;
321 algorithms.reserve(cAlgorithms.size());
322
323 std::transform(std::cbegin(cAlgorithms), std::cend(cAlgorithms), std::back_inserter(algorithms),
324 [](const auto& value) { return detail::ToFocusSharpnessAlgorithm(value); });
325 return algorithms;
326 }
327
343 {
344 archive.SetString("SharpnessAlgorithm", ToString(Get()));
345 }
346
363 {
364 Set(detail::ToFocusSharpnessAlgorithm(archive.GetString("SharpnessAlgorithm")));
365 }
366
367private:
375 std::shared_ptr<peak::afl::Controller> m_controller;
376};
377} // namespace features
378} // namespace autofeature
379} // namespace modules
380} // namespace pipeline
381} // namespace peak
The exception thrown for passing an invalid parameter to a function.
Definition peak_afl.hpp:391
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:59
virtual std::string GetString(const std::string &key) const =0
Retrieves a string value by key.
virtual void SetString(const std::string &key, const std::string &value)=0
Stores a UTF-8 string.
Interface for features that have a list of valid values.
Definition peak_afl_ifeature.hpp:169
SharpnessAlgorithm(std::shared_ptr< peak::afl::Controller > controller)
Constructs a SharpnessAlgorithm feature with the specified controller.
Definition peak_afl_sharpness_algorithm.hpp:248
void Set(const FocusSharpnessAlgorithm &value) override
Sets the focus sharpness algorithm.
Definition peak_afl_sharpness_algorithm.hpp:272
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the current sharpness algorithm to an archive.
Definition peak_afl_sharpness_algorithm.hpp:342
std::vector< FocusSharpnessAlgorithm > GetList() const override
Gets the list of supported focus sharpness algorithms.
Definition peak_afl_sharpness_algorithm.hpp:317
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes the sharpness algorithm from an archive.
Definition peak_afl_sharpness_algorithm.hpp:362
FocusSharpnessAlgorithm Get() const override
Gets the current focus sharpness algorithm.
Definition peak_afl_sharpness_algorithm.hpp:294
peak_afl_controller_sharpness_algorithm
Focus sharpness calculation algorithms.
Definition peak_afl.h:808
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_MEAN_SCORE
Mean score algorithm.
Definition peak_afl.h:851
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_SOBEL
Sobel edge detection algorithm.
Definition peak_afl.h:840
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_AUTO
Automatic algorithm selection.
Definition peak_afl.h:818
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_HISTOGRAM_VARIANCE
Histogram variance algorithm.
Definition peak_afl.h:862
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_TENENGRAD
Tenengrad gradient-based algorithm.
Definition peak_afl.h:829
@ PEAK_AFL_STATUS_INVALID_PARAMETER
Invalid parameter provided.
Definition peak_afl.h:419
@ PEAK_AFL_STATUS_ERROR
General error occurred.
Definition peak_afl.h:399
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:78
FocusSharpnessAlgorithm
Focus sharpness algorithm enumeration.
Definition peak_afl_sharpness_algorithm.hpp:39
@ Auto
Automatic algorithm selection - controller chooses the best algorithm.
Definition peak_afl_sharpness_algorithm.hpp:46
@ HistogramVariance
Histogram variance algorithm - variance-based sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:54
@ Tenengrad
Tenengrad algorithm - gradient-based sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:48
@ Sobel
Sobel algorithm - edge detection based sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:50
@ MeanScore
Mean score algorithm - statistical sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:52
@ Auto
Automatic algorithm selection - default algorithm.
Definition peak_afl_search_algorithm.hpp:47
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.h:86
Interface definitions and implementations for individual module types used within a pipeline.
Definition peak_afl_generic_auto_brightness.hpp:39
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_afl_generic_auto_brightness.hpp:37