5from ids_peak_icv
import lib_loader
16 Pixel format conversion module that transforms images to a specified output pixel format.
18 This module allows explicit control over the output pixel format and provides
19 serialization capabilities for saving/restoring state.
21 Default pixel format: PixelFormat.RGB8
23 @since ids_peak_icv 1.0
26 DEFAULT_OUTPUT_PIXEL_FORMAT: PixelFormat = PixelFormat.RGB_8
32 Initializes a pixel format conversion module with default settings.
34 @since ids_peak_icv 1.0
37 execute_and_map_return_codes(lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Create,
38 ctypes.pointer(image_converter_handle))
45 if hasattr(self,
'_handle'):
46 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Destroy(self.
_handle)
52 Returns the type of the module (used for serialization or UI).
56 @since ids_peak_icv 1.0
58 return "PixelFormatConversion"
63 Resets the output pixel format to its default value (RGB8).
65 @since ids_peak_icv 1.0
73 Returns the currently set output pixel format.
75 @return Output pixel format.
77 @since ids_peak_icv 1.0
81 @output_pixel_format.setter
85 Sets the desired output pixel format.
87 @param output_pixel_format: PixelFormat to be set as output.
89 @since ids_peak_icv 1.0
93 def process(self, input_image: Image) -> Image:
96 Processes the input image, performing mono conversion if enabled.
97 This function converts the input image to a monochrome format if the module is enabled.
98 The output image preserves the bit depth of the input. If the module is disabled,
99 the input image is returned unchanged.
101 @param input_image: The input image to convert.
102 @return The processed image in mono format if enabled; otherwise, the original image.
104 @since ids_peak_icv 1.0
114 execute_and_map_return_codes(
115 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Convert, self.
_handle, input_image._handle,
118 ctypes.pointer(output_image_handle))
120 return Image(_handle=output_image_handle)
125 Frees unused internal buffers.
127 This module uses pre-allocated internal buffers to accelerate conversions.
128 When the image size or pixel format changes, new buffers are allocated, which may cause
129 the internal buffer pool to grow over time. This function can be used to release
130 unused buffers and reduce memory usage.
132 Avoid calling this function too frequently (e.g., after every resize or format change),
133 as it introduces some overhead.
135 @since ids_peak_icv 1.0
138 execute_and_map_return_codes(
139 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_ReleaseBuffers, self.
_handle)
146 Serializes the object's internal state into the provided archive.
148 This function populates the given archive with all parameters required to fully represent the current state of the object.
149 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
150 in a consistent and structured format.
152 @return The serialized module's internal state.
154 @since ids_peak_icv 1.0
162 Restores the object's state from the provided archive.
164 This function reads and applies all necessary parameters from the given archive to reconstruct the internal state of the object.
165 It ensures that the object is restored to a valid and consistent state.
167 @param archive: The source archive containing the serialized parameters.
169 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
170 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version.
172 @note This function requires that the archive contains all expected fields as produced by a corresponding serialize() call.
174 @since ids_peak_icv 1.0
178 self.
_output_pixel_format = PixelFormat.create_from_string_value(archive.get(
"OutputPixelFormat", str))
Image Class for working with algorithms.
Base class for all pipeline modules.