IDS peak ICV v1.1.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
111 void Deserialize(const peak::common::serialization::IArchive& archive) override;
112
120 void SetEnabled(bool enabled) override;
121
129 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
130
138 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
139
145 void ResetToDefault() override;
146
160 void SetLevel(uint32_t level);
161
169 PEAK_COMMON_NO_DISCARD uint32_t GetLevel() const;
170
178 PEAK_COMMON_NO_DISCARD peak::common::IntervalU GetLevelRange() const;
179
195 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
196
214 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
215
216private:
217 static constexpr int moduleVersion{ 1 };
218 static constexpr auto levelKey{ "Level" };
219
220 uint32_t m_level{ 0 };
221
222 bool m_enabled{ true };
223};
224
226{
227 m_enabled = other.m_enabled;
228}
229
231{
232 if (this != &other)
233 {
234 m_enabled = other.m_enabled;
235 }
236
237 return *this;
238}
239
241{
242 archive.SetInt("Version", moduleVersion);
243 archive.SetBool("Enabled", IsEnabled());
244
245 archive.SetInt(levelKey, m_level);
246}
247
249{
250 const auto version = archive.GetInt("Version");
252
253 SetEnabled(archive.GetBool("Enabled"));
254
255 m_level = static_cast<uint32_t>(archive.GetInt(levelKey));
256}
257
258inline void SharpeningModule::SetEnabled(bool enabled)
259{
260 m_enabled = enabled;
261}
262
264{
265 return m_enabled;
266}
267
268inline const char* SharpeningModule::GetType() const
269{
270 return "Sharpening";
271}
272
274{
275 m_level = 0;
276}
277
278inline void SharpeningModule::SetLevel(const uint32_t level)
279{
280 auto range = GetLevelRange();
281 if (level < range.GetMinimum() || level > range.GetMaximum())
282 {
283 throw peak::icv::OutOfRangeException(std::string("The given level value " + std::to_string(level) + " is out of range!"));
284 }
285 m_level = level;
286}
287
288inline uint32_t SharpeningModule::GetLevel() const
289{
290 return m_level;
291}
292
294{
295 peak_common_interval_u cRange{};
297 return PEAK_ICV_C_ABI_PREFIX peak_icv_ImageFilter_Sharpening_GetRange(&cRange);
298 });
299
300 return { cRange.minimum, cRange.maximum };
301}
302
304{
305 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
306}
307
309{
310 if (!IsEnabled() || m_level == 0)
311 {
312 return input;
313 }
314
315 const auto& inputImage = input.AnyCast<peak::icv::Image>();
316
317 const auto pixelFormat = inputImage.GetPixelFormat();
318 const peak::common::PixelFormatInfo info(pixelFormat);
319 const auto isSupportedMonoImage = pixelFormat == peak::common::PixelFormat::Mono8
323 const auto isSupportedColorImage = isColorImage && pixelFormat != peak::common::PixelFormat::RGB10p32
324 && pixelFormat != peak::common::PixelFormat::BGR10p32;
325 if (!isSupportedMonoImage && !isSupportedColorImage)
326 {
327 return input;
328 }
329
330 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
331
333 return PEAK_ICV_C_ABI_PREFIX peak_icv_ImageFilter_Sharpening_ProcessInPlace(inputImageHandle, m_level);
334 });
335
336 return peak::common::Any{ inputImage };
337}
338
339} // namespace detail
340} // namespace pipeline
341} // 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.
@ 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)