IDS peak AFL v1.8.0
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{
28
52
66{
67 if (algorithm == FocusSharpnessAlgorithm::Auto)
68 {
69 return "Auto";
70 }
72 {
73 return "HistogramVariance";
74 }
76 {
77 return "MeanScore";
78 }
79 if (algorithm == FocusSharpnessAlgorithm::Sobel)
80 {
81 return "Sobel";
82 }
84 {
85 return "Tenengrad";
86 }
87 throw peak::common::InvalidParameterException("The given focus sharpness algorithm is unknown!");
88}
89
108inline std::ostream& operator<<(std::ostream& os, FocusSharpnessAlgorithm algorithm)
109{
110 return os << ToString(algorithm);
111}
112
113namespace features
114{
115
116namespace detail
117{
118PEAK_COMMON_NO_DISCARD inline FocusSharpnessAlgorithm ToFocusSharpnessAlgorithm(const std::string& algorithm)
119{
120 if (algorithm == "Auto")
121 {
123 }
124 if (algorithm == "Tenengrad")
125 {
127 }
128 if (algorithm == "Sobel")
129 {
131 }
132 if (algorithm == "MeanScore")
133 {
135 }
136 if (algorithm == "HistogramVariance")
137 {
139 }
140
141 throw peak::common::InvalidParameterException("The given focus sharpness algorithm " + algorithm + " is unknown!");
142}
143
145{
146 switch (algorithm)
147 {
158 }
159
160 throw peak::common::InternalErrorException("Invalid focus sharpness algorithm!");
161}
162
164{
165 switch (algorithm)
166 {
177 }
178
179 throw peak::common::InternalErrorException("Invalid focus sharpness algorithm!");
180}
181
182} // namespace detail
183
213class SharpnessAlgorithm : public IListFeature<FocusSharpnessAlgorithm>
214{
215public:
228 explicit SharpnessAlgorithm(std::shared_ptr<peak::afl::Controller> controller)
229 : m_controller{ std::move(controller) }
230 {}
231
252 void Set(const FocusSharpnessAlgorithm& value) override
253 {
254 m_controller->SetSharpnessAlgorithm(detail::ToCType(value));
255 }
256
275 {
276 return detail::ToFocusSharpnessAlgorithm(m_controller->GetSharpnessAlgorithm());
277 }
278
297 PEAK_COMMON_NO_DISCARD std::vector<FocusSharpnessAlgorithm> GetList() const override
298 {
299 const auto cAlgorithms = m_controller->GetSharpnessAlgorithmList();
300 std::vector<FocusSharpnessAlgorithm> algorithms;
301 algorithms.reserve(cAlgorithms.size());
302
303 std::transform(std::cbegin(cAlgorithms), std::cend(cAlgorithms), std::back_inserter(algorithms),
304 [](const auto& value) { return detail::ToFocusSharpnessAlgorithm(value); });
305 return algorithms;
306 }
307
323 {
324 archive.SetString("SharpnessAlgorithm", ToString(Get()));
325 }
326
343 {
344 Set(detail::ToFocusSharpnessAlgorithm(archive.GetString("SharpnessAlgorithm")));
345 }
346
347private:
355 std::shared_ptr<peak::afl::Controller> m_controller;
356};
357
358} // namespace features
359} // namespace autofeature
360} // namespace modules
361} // namespace pipeline
362} // namespace peak
Thrown when a function receives an invalid parameter.
Definition peak_common_exceptions.hpp:50
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:59
virtual PEAK_COMMON_NO_DISCARD 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:171
SharpnessAlgorithm(std::shared_ptr< peak::afl::Controller > controller)
Constructs a SharpnessAlgorithm feature with the specified controller.
Definition peak_afl_sharpness_algorithm.hpp:228
PEAK_COMMON_NO_DISCARD std::vector< FocusSharpnessAlgorithm > GetList() const override
Gets the list of supported focus sharpness algorithms.
Definition peak_afl_sharpness_algorithm.hpp:297
void Set(const FocusSharpnessAlgorithm &value) override
Sets the focus sharpness algorithm.
Definition peak_afl_sharpness_algorithm.hpp:252
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the current sharpness algorithm to an archive.
Definition peak_afl_sharpness_algorithm.hpp:322
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes the sharpness algorithm from an archive.
Definition peak_afl_sharpness_algorithm.hpp:342
PEAK_COMMON_NO_DISCARD FocusSharpnessAlgorithm Get() const override
Gets the current focus sharpness algorithm.
Definition peak_afl_sharpness_algorithm.hpp:274
PEAK_COMMON_NO_DISCARD std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:79
FocusSharpnessAlgorithm
Focus sharpness algorithm enumeration.
Definition peak_afl_sharpness_algorithm.hpp:40
@ Auto
Automatic algorithm selection - controller chooses the best algorithm.
Definition peak_afl_sharpness_algorithm.hpp:42
@ HistogramVariance
Histogram variance algorithm - variance-based sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:50
@ Tenengrad
Tenengrad algorithm - gradient-based sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:44
@ Sobel
Sobel algorithm - edge detection based sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:46
@ MeanScore
Mean score algorithm - statistical sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:48
@ Auto
Automatic algorithm selection - default algorithm.
Definition peak_afl_search_algorithm.hpp:42
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.hpp:91
peak_afl_controller_sharpness_algorithm
Focus sharpness calculation algorithms.
Definition peak_afl.h:541
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_MEAN_SCORE
Mean score algorithm.
Definition peak_afl.h:583
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_SOBEL
Sobel edge detection algorithm.
Definition peak_afl.h:572
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_AUTO
Automatic algorithm selection.
Definition peak_afl.h:550
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_HISTOGRAM_VARIANCE
Histogram variance algorithm.
Definition peak_afl.h:594
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_TENENGRAD
Tenengrad gradient-based algorithm.
Definition peak_afl.h:561
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