IDS peak AFL v2.1.0
Loading...
Searching...
No Matches
peak_afl_sharpness_algorithm.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
11
13
14#include <memory>
15
16namespace peak
17{
18namespace pipeline
19{
20namespace modules
21{
22namespace autofeature
23{
35{
42 Auto PEAK_AFL_DEPRECATED_ENUM_ATTR,
51};
52
65PEAK_COMMON_NO_DISCARD inline std::string ToString(FocusSharpnessAlgorithm algorithm)
66{
67 // clang-format off
68 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
69 if (algorithm == FocusSharpnessAlgorithm::Auto)
70 {
71 return "Auto";
72 }
73 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
74 // clang-format on
76 {
77 return "HistogramVariance";
78 }
80 {
81 return "MeanScore";
82 }
83 if (algorithm == FocusSharpnessAlgorithm::Sobel)
84 {
85 return "Sobel";
86 }
88 {
89 return "Tenengrad";
90 }
92 "The given focus sharpness algorithm is unknown!", PEAK_AFL_STATUS_INVALID_PARAMETER);
93}
94
113inline std::ostream& operator<<(std::ostream& os, FocusSharpnessAlgorithm algorithm)
114{
115 return os << ToString(algorithm);
116}
117
118namespace features
119{
120namespace detail
121{
122PEAK_COMMON_NO_DISCARD inline FocusSharpnessAlgorithm ToFocusSharpnessAlgorithm(const std::string& algorithm)
123{
124 if (algorithm == "Auto")
125 {
126 // clang-format off
127 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
129 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
130 // clang-format on
131 }
132 if (algorithm == "Tenengrad")
133 {
135 }
136 if (algorithm == "Sobel")
137 {
139 }
140 if (algorithm == "MeanScore")
141 {
143 }
144 if (algorithm == "HistogramVariance")
145 {
147 }
148
149 throw peak::afl::error::InvalidParameterException(
150 "The given focus sharpness algorithm " + algorithm + " is unknown!", PEAK_AFL_STATUS_INVALID_PARAMETER);
151}
152
153PEAK_COMMON_NO_DISCARD inline FocusSharpnessAlgorithm ToFocusSharpnessAlgorithm(peak_afl_controller_sharpness_algorithm algorithm)
154{
155 // clang-format off
156 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
157 switch (algorithm)
158 {
169 }
170 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
171 // clang-format on
172
173 throw peak::afl::error::InternalErrorException("Invalid focus sharpness algorithm!", PEAK_AFL_STATUS_ERROR);
174}
175
176PEAK_COMMON_NO_DISCARD inline peak_afl_controller_sharpness_algorithm ToCType(FocusSharpnessAlgorithm algorithm)
177{
178 // clang-format off
179 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
180 switch (algorithm)
181 {
192 }
193 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
194 // clang-format on
195
196 throw peak::afl::error::InternalErrorException("Invalid focus sharpness algorithm!", PEAK_AFL_STATUS_ERROR);
197}
198} // namespace detail
199
229class SharpnessAlgorithm : public IListFeature<FocusSharpnessAlgorithm>
230{
231public:
244 explicit SharpnessAlgorithm(std::shared_ptr<peak::afl::Controller> controller)
245 : m_controller{ std::move(controller) }
246 {}
247
268 void Set(const FocusSharpnessAlgorithm& value) override
269 {
270 m_controller->SetSharpnessAlgorithm(detail::ToCType(value));
271 }
272
290 PEAK_COMMON_NO_DISCARD FocusSharpnessAlgorithm Get() const override
291 {
292 return detail::ToFocusSharpnessAlgorithm(m_controller->GetSharpnessAlgorithm());
293 }
294
313 PEAK_COMMON_NO_DISCARD std::vector<FocusSharpnessAlgorithm> GetList() const override
314 {
315 const auto cAlgorithms = m_controller->GetSharpnessAlgorithmList();
316 std::vector<FocusSharpnessAlgorithm> algorithms;
317 algorithms.reserve(cAlgorithms.size());
318
319 std::transform(std::cbegin(cAlgorithms), std::cend(cAlgorithms), std::back_inserter(algorithms),
320 [](const auto& value) { return detail::ToFocusSharpnessAlgorithm(value); });
321 return algorithms;
322 }
323
339 {
340 archive.SetString("SharpnessAlgorithm", ToString(Get()));
341 }
342
359 {
360 Set(detail::ToFocusSharpnessAlgorithm(archive.GetString("SharpnessAlgorithm")));
361 }
362
363private:
371 std::shared_ptr<peak::afl::Controller> m_controller;
372};
373} // namespace features
374} // namespace autofeature
375} // namespace modules
376} // namespace pipeline
377} // namespace peak
The exception thrown for passing an invalid parameter to a function.
Definition peak_afl.hpp:436
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:54
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:165
SharpnessAlgorithm(std::shared_ptr< peak::afl::Controller > controller)
Constructs a SharpnessAlgorithm feature with the specified controller.
Definition peak_afl_sharpness_algorithm.hpp:244
void Set(const FocusSharpnessAlgorithm &value) override
Sets the focus sharpness algorithm.
Definition peak_afl_sharpness_algorithm.hpp:268
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the current sharpness algorithm to an archive.
Definition peak_afl_sharpness_algorithm.hpp:338
std::vector< FocusSharpnessAlgorithm > GetList() const override
Gets the list of supported focus sharpness algorithms.
Definition peak_afl_sharpness_algorithm.hpp:313
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes the sharpness algorithm from an archive.
Definition peak_afl_sharpness_algorithm.hpp:358
FocusSharpnessAlgorithm Get() const override
Gets the current focus sharpness algorithm.
Definition peak_afl_sharpness_algorithm.hpp:290
peak_afl_controller_sharpness_algorithm
Focus sharpness calculation algorithms.
Definition peak_afl.h:805
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_MEAN_SCORE
Mean score algorithm.
Definition peak_afl.h:848
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_SOBEL
Sobel edge detection algorithm.
Definition peak_afl.h:837
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_AUTO
Automatic algorithm selection.
Definition peak_afl.h:815
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_HISTOGRAM_VARIANCE
Histogram variance algorithm.
Definition peak_afl.h:859
@ PEAK_AFL_CONTROLLER_SHARPNESS_ALGORITHM_TENENGRAD
Tenengrad gradient-based algorithm.
Definition peak_afl.h:826
@ PEAK_AFL_STATUS_INVALID_PARAMETER
Invalid parameter provided.
Definition peak_afl.h:416
@ PEAK_AFL_STATUS_ERROR
General error occurred.
Definition peak_afl.h:396
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:74
FocusSharpnessAlgorithm
Focus sharpness algorithm enumeration.
Definition peak_afl_sharpness_algorithm.hpp:35
@ 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:43
Interface definitions and implementations for individual module types used within a pipeline.
Definition peak_afl_generic_auto_brightness.hpp:35
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_afl_generic_auto_brightness.hpp:33