3from ids_peak_common.datatypes.pixelformat
import PixelFormat
4from ids_peak_icv
import lib_loader
14 Mono conversion is an image pipeline module that converts images to a monochrome format.
16 The mono conversion module performs a mono (grayscale) conversion on input images.
17 When enabled, it converts the input image to a mono format while preserving the input bit depth.
18 If disabled, the input image is passed through unchanged.
20 @since ids_peak_icv 1.0
26 Initializes a MonoConversionModule with default settings.
28 @since ids_peak_icv 1.0
33 execute_and_map_return_codes(lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Create,
34 ctypes.pointer(image_converter_handle))
39 if hasattr(self,
'_handle'):
40 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Destroy(self.
_handle)
46 Returns the type of the module for serialization purposes.
50 @since ids_peak_icv 1.0
52 return "MonoConversion"
57 Calling this method has no effect.
59 @since ids_peak_icv 1.0
63 def process(self, input_image: Image) -> Image:
66 Converts the input image to the configured output pixel format.
68 @note This operation disregards any specified image regions
69 and processes the full image.
71 @param input_image: The input image to convert.
73 @return Converted image in the configured pixel format.
75 @since ids_peak_icv 1.0
82 if input_image.pixel_format == output_pixel_format:
86 execute_and_map_return_codes(
87 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Convert, self.
_handle, input_image._handle,
89 output_pixel_format.value),
90 ctypes.pointer(output_image_handle))
92 return Image(_handle=output_image_handle)
97 Frees unused internal buffers.
99 This module uses pre-allocated internal buffers to accelerate conversions.
100 When the image size or pixel format changes, new buffers are allocated, which may cause
101 the internal buffer pool to grow over time. This function can be used to release
102 unused buffers and reduce memory usage.
104 @note Avoid calling this function too frequently (e.g., after every resize or format change),
105 as it introduces some overhead.
107 @since ids_peak_icv 1.0
110 execute_and_map_return_codes(
111 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_ReleaseBuffers, self.
_handle)
118 if (input_pixel_format.is_single_channel
and input_pixel_format.has_intensity_channel):
119 return input_pixel_format
121 bit_depth = input_pixel_format.storage_bits_per_channel
124 return PixelFormat.MONO_8
126 return PixelFormat.MONO_10
128 return PixelFormat.MONO_12
129 return PixelFormat.MONO_16
Image Class for working with algorithms.
Base class for all pipeline modules.
bool enabled(self)
Gets whether this module is enabled.
None enabled(self, bool enabled)
Enables or disables the module.
Mono conversion is an image pipeline module that converts images to a monochrome format.
None reset_to_default(self)
Calling this method has no effect.
None release_buffers(self)
Frees unused internal buffers.
str type(self)
Returns the type of the module for serialization purposes.
PixelFormat _get_output_format(PixelFormat input_pixel_format)
Image process(self, Image input_image)
Converts the input image to the configured output pixel format.
None __init__(self)
Initializes a MonoConversionModule with default settings.