IDS peak ICV v1.3.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
163 PEAK_COMMON_NO_DISCARD peak::icv::Image Process(const peak::icv::Image& input) const;
164
179 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
180
194 void ReleaseBuffers() const;
195
196private:
197 PEAK_COMMON_NO_DISCARD static peak::common::PixelFormat GetOutputFormat(peak::common::PixelFormat inputFormat);
198
199 constexpr static int moduleVersion{ 1 };
200
201 bool m_enabled{ true };
202 peak_icv_image_converter_handle m_handle{};
203};
204
206{
208 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Create(&m_handle);
209 });
210}
211
213{
214 if (m_handle != nullptr)
215 {
216 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Destroy(m_handle);
217 }
218}
219
221{
222 m_enabled = other.m_enabled;
223 std::swap(m_handle, other.m_handle);
224}
225
227{
228 if (this != &other)
229 {
230 m_enabled = other.m_enabled;
231 std::swap(m_handle, other.m_handle);
232 }
233
234 return *this;
235}
236
238{
239 archive.SetBool("Enabled", IsEnabled());
240 archive.SetInt("Version", moduleVersion);
241}
242
244{
245 const auto version = archive.GetInt("Version");
247
248 SetEnabled(archive.GetBool("Enabled"));
249}
250
251inline void MonoConversionModule::SetEnabled(bool enabled)
252{
253 m_enabled = enabled;
254}
255
257{
258 return m_enabled;
259}
260
261inline const char* MonoConversionModule::GetType() const
262{
263 return "MonoConversion";
264}
265
266inline peak::common::PixelFormat MonoConversionModule::GetOutputFormat(peak::common::PixelFormat inputFormat)
267{
268 const peak::common::PixelFormatInfo info(inputFormat);
269
270 if (info.IsSingleChannel() && info.HasIntensityChannel())
271 {
272 return inputFormat;
273 }
274
275 const auto bitDepth = info.GetStorageBitsPerChannel();
276
277 if (bitDepth <= 8)
278 {
280 }
281 if (bitDepth <= 10)
282 {
284 }
285 if (bitDepth <= 12)
286 {
288 }
290}
291
293{
294 return Process(peak::common::Any(input)).AnyCast<peak::icv::Image>();
295}
296
298{
299 if (!IsEnabled())
300 {
301 return input;
302 }
303
304 const auto& inputImage = input.AnyCast<peak::icv::Image>();
305
306 const auto inputFormat = inputImage.GetPixelFormat();
307 const auto outputFormat = GetOutputFormat(inputFormat);
308
309 if (inputFormat == outputFormat)
310 {
311 return input;
312 }
313
314 auto* const inputImageHandle = peak::common::detail::BackendAccessor<peak::icv::Image>::BackendHandle(inputImage);
315 peak_icv_image_handle outputHandle = nullptr;
316
318 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_Convert(
319 m_handle, inputImageHandle, peak::common::detail::CppPixelFormatToCPixelFormat(outputFormat), &outputHandle);
320 });
321
322 return peak::common::Any(peak::common::detail::BackendAccessor<peak::icv::Image>::CreateInstance(outputHandle));
323}
324
326{
328 return PEAK_ICV_C_ABI_PREFIX peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(m_handle);
329 });
330}
331
332} // namespace detail
333} // namespace pipeline
334} // 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
Converts the input image to the configured output pixel format.
void SetEnabled(bool enabled) override
Enables or disables the 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
Calling this method has no effect.
bool IsEnabled() const override
Gets whether this 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