IDS peak ICV v1.2.0
Loading...
Searching...
No Matches
peak_icv_mono_conversion_module.hpp
Go to the documentation of this file.
1
11#pragma once
12
16#include <peak_icv_c/algorithms/preprocessing/peak_icv_image_converter.h>
17
18namespace peak
19{
20namespace pipeline
21{
22namespace detail
23{
24
37{
38public:
45
51 ~MonoConversionModule() override;
52
61
68
77
84
96 void Serialize(peak::common::serialization::IArchive& archive) const override;
97
98
114 void Deserialize(const peak::common::serialization::IArchive& archive) override;
115
123 void SetEnabled(bool enabled) override;
124
132 PEAK_COMMON_NO_DISCARD bool IsEnabled() const override;
133
141 PEAK_COMMON_NO_DISCARD const char* GetType() const override;
142
148 void ResetToDefault() override
149 {}
150
165 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
166
184 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
185
199 void ReleaseBuffers() const;
200
201private:
202 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat GetOutputFormat(peak::common::PixelFormat inputFormat);
203
204 constexpr static int moduleVersion{ 1 };
205
206 bool m_enabled{ true };
207 peak_icv_image_converter_handle m_handle{};
208};
209
211{
213 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
214 });
215}
216
218{
219 if (m_handle != nullptr)
220 {
221 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
222 }
223}
224
226{
227 m_enabled = other.m_enabled;
228 std::swap(m_handle, other.m_handle);
229}
230
232{
233 if (this != &other)
234 {
235 m_enabled = other.m_enabled;
236 std::swap(m_handle, other.m_handle);
237 }
238
239 return *this;
240}
241
243{
244 archive.SetBool("Enabled", IsEnabled());
245 archive.SetInt("Version", moduleVersion);
246}
247
249{
250 const auto version = archive.GetInt("Version");
252
253 SetEnabled(archive.GetBool("Enabled"));
254}
255
256inline void MonoConversionModule::SetEnabled(bool enabled)
257{
258 m_enabled = enabled;
259}
260
262{
263 return m_enabled;
264}
265
266inline const char* MonoConversionModule::GetType() const
267{
268 return "MonoConversion";
269}
270
271inline peak::common::PixelFormat MonoConversionModule::GetOutputFormat(peak::common::PixelFormat inputFormat)
272{
273 const peak::common::PixelFormatInfo info(inputFormat);
274
275 if (info.IsSingleChannel() && info.HasIntensityChannel())
276 {
277 return inputFormat;
278 }
279
280 const auto bitDepth = info.GetStorageBitsPerChannel();
281
282 if (bitDepth <= 8)
283 {
285 }
286 if (bitDepth <= 10)
287 {
289 }
290 if (bitDepth <= 12)
291 {
293 }
295}
296
298{
299 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
300}
301
303{
304 if (!IsEnabled())
305 {
306 return input;
307 }
308
309 const auto& inputImage = input.AnyCast<peak::icv::Image>();
310
311 const auto inputFormat = inputImage.GetPixelFormat();
312 const auto outputFormat = GetOutputFormat(inputFormat);
313
314 if (inputFormat == outputFormat)
315 {
316 return input;
317 }
318
319 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
320 peak_icv_image_handle outputHandle = nullptr;
321
323 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
324 m_handle, inputImageHandle, peak::common::detail::CppPixelFormatToCPixelFormat(outputFormat), &outputHandle);
325 });
326
327 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
328}
329
331{
333 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
334 });
335}
336
337} // namespace detail
338} // namespace pipeline
339} // 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.
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.
Mono conversion is an image pipeline module that converts images to a monochrome format.
MonoConversionModule()
Creates an instance of class MonoConversion.
const char * GetType() const override
Returns the type of the module for serialization purposes.
MonoConversionModule(const MonoConversionModule &other)=delete
Copy constructor for class MonoConversionModule is deleted.
void ReleaseBuffers() const
Frees unused internal buffers.
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, performing mono conversion if enabled.
void SetEnabled(bool enabled) override
Sets the enabled state of this module.
MonoConversionModule & operator=(const MonoConversionModule &other)=delete
Copy assignment for class MonoConversionModule is deleted.
void Deserialize(const peak::common::serialization::IArchive &archive) override
Restores the object's state from the provided archive.
void ResetToDefault() override
Does nothing for the mono conversion module.
bool IsEnabled() const override
Checks if the module is currently enabled.
Interface for a module used within a pipeline.
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
@ Mono12
Mono 12-Bit pixel format.
@ Mono16
Mono 16-Bit pixel format.
@ Mono10
Mono 10-Bit pixel format.
@ Mono8
Mono 8-Bit pixel format.
constexpr peak_common_pixel_format CppPixelFormatToCPixelFormat(PixelFormat pixelFormat) noexcept
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
void ValidateVersion(int64_t version, const std::string &moduleName)
peak_icv_image * peak_icv_image_handle