IDS peak ICV v1.0.0
Loading...
Searching...
No Matches
peak_icv_sharpening_module.hpp
Go to the documentation of this file.
1
11#pragma once
12
17#include <peak_icv_c/algorithms/filters/peak_icv_image_filter_sharpening.h>
18
19namespace peak
20{
21namespace pipeline
22{
23namespace detail
24{
25
34{
35public:
41 SharpeningModule() = default;
42
48 ~SharpeningModule() override = default;
49
57 SharpeningModule(const SharpeningModule& other) = delete;
58
64 SharpeningModule(SharpeningModule&& other) noexcept;
65
74
81
93 void Serialize(peak::common::serialization::IArchive& archive) const override;
94
95
110 void Deserialize(const peak::common::serialization::IArchive& archive) override;
111
119 void SetEnabled(bool enabled) override;
120
128 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
129
137 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
138
144 void ResetToDefault() override;
145
159 void SetLevel(uint32_t level);
160
168 PEAK_COMMON_NO_DISCARD uint32_t GetLevel() const;
169
178
195
214
215private:
216 static constexpr int moduleVersion{ 1 };
217 static constexpr auto levelKey{ "Level" };
218
219 uint32_t m_level{ 0 };
220
221 bool m_enabled{ true };
222};
223
225{
226 m_enabled = other.m_enabled;
227}
228
230{
231 if (this != &other)
232 {
233 m_enabled = other.m_enabled;
234 }
235
236 return *this;
237}
238
240{
241 archive.SetInt("Version", moduleVersion);
242 archive.SetBool("Enabled", IsEnabled());
243
244 archive.SetInt(levelKey, m_level);
245}
246
248{
249 const auto version = archive.GetInt("Version");
251
252 SetEnabled(archive.GetBool("Enabled"));
253
254 m_level = static_cast<uint32_t>(archive.GetInt(levelKey));
255}
256
257inline void SharpeningModule::SetEnabled(bool enabled)
258{
259 m_enabled = enabled;
260}
261
263{
264 return m_enabled;
265}
266
267inline const char* SharpeningModule::GetType() const
268{
269 return "Sharpening";
270}
271
273{
274 m_level = 0;
275}
276
277inline void SharpeningModule::SetLevel(const uint32_t level)
278{
279 auto range = GetLevelRange();
280 if (level < range.GetMinimum() || level > range.GetMaximum())
281 {
282 throw peak::icv::OutOfRangeException(std::string("The given level value " + std::to_string(level) + " is out of range!"));
283 }
284 m_level = level;
285}
286
287inline uint32_t SharpeningModule::GetLevel() const
288{
289 return m_level;
290}
291
293{
294 peak_common_interval_u cRange{};
296 return PEAK_ICV_C_ABI_PREFIX peak_icv_ImageFilter_Sharpening_GetRange(&cRange);
297 });
298
299 return { cRange.minimum, cRange.maximum };
300}
301
303{
304 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
305}
306
308{
309 if (!IsEnabled() || m_level == 0)
310 {
311 return input;
312 }
313
314 const auto& inputImage = input.AnyCast<peak::icv::Image>();
315
316 const auto pixelFormat = inputImage.GetPixelFormat();
317 const peak::common::PixelFormatInfo info(pixelFormat);
318 const auto isSupportedMonoImage = pixelFormat == peak::common::PixelFormat::Mono8
322 const auto isSupportedColorImage = isColorImage && pixelFormat != peak::common::PixelFormat::RGB10p32
323 && pixelFormat != peak::common::PixelFormat::BGR10p32;
324 if (!isSupportedMonoImage && !isSupportedColorImage)
325 {
326 return input;
327 }
328
329 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
330
332 return PEAK_ICV_C_ABI_PREFIX peak_icv_ImageFilter_Sharpening_ProcessInPlace(inputImageHandle, m_level);
333 });
334
335 return peak::common::Any{ inputImage };
336}
337
338} // namespace detail
339} // namespace pipeline
340} // 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.
Represents a continuous numeric interval with inclusive lower and upper bounds.
Interface for a hierarchical key-value archive system.
virtual void SetBool(const std::string &key, bool value)=0
Stores a boolean value.
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.
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.
Thrown when a value is outside the allowed range.
Sharpening is an image pipeline module that applies a sharpening filter to enhance image detail.
const char * GetType() const override
Returns the type of the module for serialization purposes.
SharpeningModule & operator=(const SharpeningModule &other)=delete
Copy assignment for class SharpeningModule is deleted.
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 sharpened output image.
void SetEnabled(bool enabled) override
Sets the enabled state of this module.
void SetLevel(uint32_t level)
Sets the sharpness level.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
uint32_t GetLevel() const
Retrieves the current sharpness level.
void ResetToDefault() override
Resets the sharpness level to the default value.
SharpeningModule()=default
Creates an instance of class SharpeningModule with default values.
SharpeningModule(const SharpeningModule &other)=delete
Copy constructor for class SharpeningModule is deleted.
bool IsEnabled() const override
Checks if the module is currently enabled.
peak::common::IntervalU GetLevelRange() const
Returns the valid range of sharpness levels.
Interface for a module used within a pipeline.
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
@ Mono12
Mono 12-Bit pixel format.
@ BGR10p32
BGR 10-Bit packed 32-bit format.
@ Mono10
Mono 10-Bit pixel format.
@ Mono8
Mono 8-Bit pixel format.
@ RGB10p32
RGB 10-Bit packed 32-bit format.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)