5from ids_peak_icv
import lib_loader
19 Debayer is an image pipeline module that converts Bayer RAW images into standard color formats.
21 It performs demosaicing on Bayer-pattern RAW images, converting them into full-color images
22 using configurable channel layouts such as RGB, BGR, RGBA, or BGRA. The bit depth of the output
23 is inferred from the input, depending on the selected processing policy.
25 Default configuration:
27 - Channel layout: DebayerChannelLayout.RGB
28 - Conversion policy: DebayerConversionPolicy.BAYER_ONLY
30 - Processing policy: ProcessingPolicy.FAST
32 @ingroup ids_peak_icv_python_pipeline_modules
33 @since ids_peak_icv 1.0
36 DEFAULT_CHANNEL_LAYOUT: DebayerChannelLayout = DebayerChannelLayout.RGB
37 DEFAULT_CONVERSION_POLICY: DebayerConversionPolicy = DebayerConversionPolicy.BAYER_ONLY
38 DEFAULT_TARGET_BIT_DEPTH: int = 8
39 DEFAULT_POLICY: ProcessingPolicy = ProcessingPolicy.FAST
44 Creates an instance of the debayer module.
45 @since ids_peak_icv 1.0
50 execute_and_map_return_codes(
51 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Create,
52 ctypes.pointer(image_converter_handle)
62 if hasattr(self,
"_handle")
and self.
_handle:
63 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Destroy(self.
_handle)
69 Returns the type of the module for serialization purposes.
71 @since ids_peak_icv 1.0
79 Get the output channel layout used for debayered images.
81 @return The currently configured DebayerChannelLayout.
82 @since ids_peak_icv 1.0
86 @channel_layout.setter
90 Set the output channel layout for debayered images.
92 This controls the order and number of color channels in the converted image.
93 The bit depth is automatically inherited from the input Bayer image.
95 @param layout: Desired channel layout
96 @since ids_peak_icv 1.0
104 Get the conversion policy.
105 @return The currently configured DebayerConversionPolicy.
106 @since ids_peak_icv 1.0
110 @conversion_policy.setter
114 Set the debayer conversion policy.
116 This policy determines which types of input images will be converted.
117 All other image types are passed through unchanged.
119 @param policy: Desired conversion policy.
120 @since ids_peak_icv 1.0
128 Get the target bit depth for processed images.
129 @return Target bit depth as an integer.
130 @since ids_peak_icv 1.0
134 @target_bit_depth.setter
138 Set the target bit depth for processed images.
140 The effective output bit depth depends on the selected :class:`ProcessingPolicy`:
142 - **FAST**: The minimum of input bit depth and target bit depth.
143 - **BALANCED**: Equal to input bit depth.
144 - **ENHANCED**: The maximum of input bit depth and target bit depth.
146 @param bit_depth: Desired target bit depth (e.g., 8, 10, 12).
147 @since ids_peak_icv 1.0
152 def processing_policy(self) -> ProcessingPolicy:
155 Get the processing policy.
156 @return Current ProcessingPolicy value.
157 @since ids_peak_icv 1.0
161 @processing_policy.setter
162 def processing_policy(self, policy: ProcessingPolicy) ->
None:
165 Set the processing policy.
167 The processing policy defines how the target bit depth interacts
168 with the input image bit depth.
170 @param policy: Desired ProcessingPolicy.
171 @since ids_peak_icv 1.0
175 def process(self, input_image: Image) -> Image:
178 Processes the input image by applying debayering (if enabled).
180 - If the module is disabled, returns the input image unchanged.
181 - If the conversion policy indicates bypass or the image format
182 is not eligible, returns the input image unchanged.
183 - Otherwise, converts the Bayer RAW image to the configured output format.
185 @param input_image: Input image to be processed.
186 @return Processed output image.
187 @since ids_peak_icv 1.0
192 input_pixel_format = input_image.pixel_format
195 if input_pixel_format == output_format:
199 execute_and_map_return_codes(
200 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Convert,
203 ctypes.c_int(output_format.value),
204 ctypes.pointer(output_handle)
206 return Image(_handle=output_handle)
211 Resets all module settings.
213 Restores the module configuration to its default values:
214 - Channel layout = RGB
215 - Conversion policy = BAYER_ONLY
216 - Target bit depth = 8
217 - Processing policy = FAST
219 @since ids_peak_icv 1.0
229 Frees unused internal buffers.
231 This module uses pre-allocated internal buffers to accelerate conversions.
232 When the image size or pixel format changes, new buffers are allocated, which may cause
233 the internal buffer pool to grow over time. This function can be used to release
234 unused buffers and reduce memory usage.
236 Avoid calling this function too frequently (e.g., after every resize or format change),
237 as it introduces some overhead.
239 @since ids_peak_icv 1.0
241 execute_and_map_return_codes(
242 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_ReleaseBuffers,
251 Serializes the object's internal state into the provided archive.
253 This function populates the given archive with all parameters required to fully represent the current state of the object.
254 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
255 in a consistent and structured format.
257 @return The serialized module's internal state.
259 @since ids_peak_icv 1.0
268 Restores the object's state from the provided archive.
270 This function reads and applies all necessary parameters from the given archive to reconstruct the internal state of the object.
271 It ensures that the object is restored to a valid and consistent state.
273 @param archive: The source archive containing the serialized parameters.
275 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
276 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version.
278 @note This function requires that the archive contains all expected fields as produced by a corresponding serialize() call.
280 @since ids_peak_icv 1.0
284 self.
_channel_layout = DebayerChannelLayout.create_from_string_value(archive.get(
"ChannelLayout", str))
286 archive.get(
"ConversionPolicy", str))
291 if self.
_policy == ProcessingPolicy.FAST:
293 elif self.
_policy == ProcessingPolicy.ENHANCED:
295 return input_bit_depth
299 return input_pixel_format
301 if not input_pixel_format.is_single_channel:
302 return input_pixel_format
304 is_bayer = input_pixel_format.has_channel(Channel.BAYER)
305 is_mono = input_pixel_format.has_channel(Channel.INTENSITY)
307 if not is_bayer
and (
not is_mono
or self.
_conversion_policy is not DebayerConversionPolicy.BAYER_AND_MONO):
308 return input_pixel_format
310 input_bit_depth = input_pixel_format.storage_bits_per_channel
313 if output_bit_depth <= 8:
315 DebayerChannelLayout.RGB: PixelFormat.RGB_8,
316 DebayerChannelLayout.BGR: PixelFormat.BGR_8,
317 DebayerChannelLayout.RGBA: PixelFormat.RGBA_8,
318 DebayerChannelLayout.BGRA: PixelFormat.BGRA_8,
321 if output_bit_depth <= 10:
323 DebayerChannelLayout.RGB: PixelFormat.RGB_10,
324 DebayerChannelLayout.BGR: PixelFormat.BGR_10,
325 DebayerChannelLayout.RGBA: PixelFormat.RGBA_10,
326 DebayerChannelLayout.BGRA: PixelFormat.BGRA_10,
329 if output_bit_depth <= 12:
331 DebayerChannelLayout.RGB: PixelFormat.RGB_12,
332 DebayerChannelLayout.BGR: PixelFormat.BGR_12,
333 DebayerChannelLayout.RGBA: PixelFormat.RGBA_12,
334 DebayerChannelLayout.BGRA: PixelFormat.BGRA_12,
338 f
"The given input pixel format 0x{input_pixel_format.value:X} is unknown or not supported!"
Image Class for working with algorithms.
Thrown when a requested operation is not implemented or supported.
Debayer is an image pipeline module that converts Bayer RAW images into standard color formats.
ProcessingPolicy DEFAULT_POLICY
None reset_to_default(self)
Resets all module settings.
None release_buffers(self)
Frees unused internal buffers.
None deserialize(self, IArchive archive)
Restores the object's state from the provided archive.
DebayerConversionPolicy DEFAULT_CONVERSION_POLICY
DebayerChannelLayout _channel_layout
str type(self)
Returns the type of the module for serialization purposes.
int DEFAULT_TARGET_BIT_DEPTH
DebayerConversionPolicy conversion_policy(self)
Get the conversion policy.
PixelFormat _get_output_format(self, PixelFormat input_pixel_format)
DebayerChannelLayout channel_layout(self)
Get the output channel layout used for debayered images.
int target_bit_depth(self)
Get the target bit depth for processed images.
DebayerChannelLayout DEFAULT_CHANNEL_LAYOUT
Image process(self, Image input_image)
Processes the input image by applying debayering (if enabled).
None __init__(self)
Creates an instance of the debayer module.
DebayerConversionPolicy _conversion_policy
None serialize(self, IArchive archive)
Serializes the object's internal state into the provided archive.
int _get_output_bit_depth(self, int input_bit_depth)
Base class for all pipeline modules.