3from ids_peak_common.datatypes.pixelformat
import PixelFormat, Channel
4from ids_peak_common.serialization
import IArchive
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:
26 - Channel layout: DebayerChannelLayout.RGB
27 - Conversion policy: DebayerConversionPolicy.BAYER_ONLY
29 - Processing policy: ProcessingPolicy.FAST
31 @ingroup ids_peak_icv_python_pipeline_modules
32 @since ids_peak_icv 1.0
35 DEFAULT_CHANNEL_LAYOUT: DebayerChannelLayout = DebayerChannelLayout.RGB
36 DEFAULT_CONVERSION_POLICY: DebayerConversionPolicy = DebayerConversionPolicy.BAYER_ONLY
37 DEFAULT_TARGET_BIT_DEPTH: int = 8
38 DEFAULT_POLICY: ProcessingPolicy = ProcessingPolicy.FAST
43 Creates an instance of the debayer module.
44 @since ids_peak_icv 1.0
49 execute_and_map_return_codes(
50 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Create,
51 ctypes.pointer(image_converter_handle)
61 if hasattr(self,
"_handle")
and self.
_handle:
62 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Destroy(self.
_handle)
68 Returns the type of the module for serialization purposes.
72 @since ids_peak_icv 1.0
80 Get the output channel layout used for debayered images.
82 @return The currently configured DebayerChannelLayout.
84 @since ids_peak_icv 1.0
88 @channel_layout.setter
92 Set the output channel layout for debayered images.
94 This controls the order and number of color channels in the converted image.
96 @param layout: Desired channel layout
97 @since ids_peak_icv 1.0
105 Get the current conversion policy.
107 @return The currently configured DebayerConversionPolicy.
109 @since ids_peak_icv 1.0
113 @conversion_policy.setter
117 Set the debayer conversion policy.
119 This policy determines which types of input images will be converted.
120 All other image types are passed through unchanged.
122 @param policy: The desired conversion policy.
124 @since ids_peak_icv 1.0
132 Get the target bit depth for processed images.
133 @return Target bit depth as an integer.
134 @since ids_peak_icv 1.0
138 @target_bit_depth.setter
142 Set the target bit depth for processed images.
144 The effective output bit depth depends on the selected :class:`ProcessingPolicy`:
146 - **FAST**: The minimum of input bit depth and target bit depth.
147 - **BALANCED**: Equal to input bit depth.
148 - **ENHANCED**: The maximum of input bit depth and target bit depth.
150 @param bit_depth: The desired target bit depth (e.g., 8, 10, 12).
152 @since ids_peak_icv 1.0
157 def processing_policy(self) -> ProcessingPolicy:
160 Get the processing policy.
161 @return Current ProcessingPolicy value.
162 @since ids_peak_icv 1.0
166 @processing_policy.setter
167 def processing_policy(self, policy: ProcessingPolicy) ->
None:
170 Set the processing policy.
172 The processing policy defines how the target bit depth interacts
173 with the input image bit depth.
175 @param policy: The desired ProcessingPolicy.
177 @since ids_peak_icv 1.0
181 def process(self, input_image: Image) -> Image:
184 Converts a Bayer or mono image to a color image,
185 or returns the input image unchanged.
187 A demosaicing algorithm is applied according to the configured
188 conversion policy. The input image is returned unchanged if the module
189 is disabled, the policy indicates bypass, or the image format is not
190 eligible for conversion. Otherwise, the Bayer RAW image is converted
191 to the configured output format.
193 @note This operation disregards any specified image regions and processes
196 @param input_image: The input image (Bayer, mono, or already color).
198 @return The processed color image or the unmodified input image.
200 @since ids_peak_icv 1.0
205 input_pixel_format = input_image.pixel_format
208 if input_pixel_format == output_format:
212 execute_and_map_return_codes(
213 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_Convert,
216 ctypes.c_int(output_format.value),
217 ctypes.pointer(output_handle)
219 return Image(_handle=output_handle)
224 Resets all settings to their defaults.
226 Default configuration:
227 - channel_layout = RGB
228 - conversion_policy = BAYER_ONLY
229 - target_bit_depth = 8
230 - processing_policy = FAST
232 @note The enabled state does not change when calling this function.
234 @since ids_peak_icv 1.0
244 Frees unused internal buffers.
246 This module uses pre-allocated internal buffers to accelerate conversions.
247 When the image size or pixel format changes, new buffers are allocated, which may cause
248 the internal buffer pool to grow over time. This function can be used to release
249 unused buffers and reduce memory usage.
251 @note Avoid calling this function too frequently (e.g., after every resize or format change),
252 as it introduces some overhead.
254 @since ids_peak_icv 1.0
256 execute_and_map_return_codes(
257 lib_loader.dll().peak_icv_Preprocessing_ImageConverter_ReleaseBuffers,
266 Serializes the object's internal state into the provided archive.
268 This function populates the given archive with all parameters required to fully represent the current state of the object.
269 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
270 in a consistent and structured format.
272 @param archive: The target archive that will store the serialized parameters.
274 @since ids_peak_icv 1.0
283 Restores the object's state from the provided archive.
285 This function reads and applies all necessary parameters from the given archive to reconstruct the internal state of the object.
286 It ensures that the object is restored to a valid and consistent state.
288 @param archive: The source archive containing the serialized parameters.
290 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
291 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version.
293 @note This function requires that the archive contains all expected fields as produced by a corresponding serialize() call.
295 @since ids_peak_icv 1.0
299 self.
_channel_layout = DebayerChannelLayout.create_from_string_value(archive.get(
"ChannelLayout", str))
301 archive.get(
"ConversionPolicy", str))
306 if self.
_policy == ProcessingPolicy.FAST:
308 elif self.
_policy == ProcessingPolicy.ENHANCED:
310 return input_bit_depth
314 return input_pixel_format
316 if not input_pixel_format.is_single_channel:
317 return input_pixel_format
319 is_bayer = input_pixel_format.has_channel(Channel.BAYER)
320 is_mono = input_pixel_format.has_channel(Channel.INTENSITY)
322 if not is_bayer
and (
not is_mono
or self.
_conversion_policy is not DebayerConversionPolicy.BAYER_AND_MONO):
323 return input_pixel_format
325 input_bit_depth = input_pixel_format.storage_bits_per_channel
328 if output_bit_depth <= 8:
330 DebayerChannelLayout.RGB: PixelFormat.RGB_8,
331 DebayerChannelLayout.BGR: PixelFormat.BGR_8,
332 DebayerChannelLayout.RGBA: PixelFormat.RGBA_8,
333 DebayerChannelLayout.BGRA: PixelFormat.BGRA_8,
336 if output_bit_depth <= 10:
338 DebayerChannelLayout.RGB: PixelFormat.RGB_10,
339 DebayerChannelLayout.BGR: PixelFormat.BGR_10,
340 DebayerChannelLayout.RGBA: PixelFormat.RGBA_10,
341 DebayerChannelLayout.BGRA: PixelFormat.BGRA_10,
344 if output_bit_depth <= 12:
346 DebayerChannelLayout.RGB: PixelFormat.RGB_12,
347 DebayerChannelLayout.BGR: PixelFormat.BGR_12,
348 DebayerChannelLayout.RGBA: PixelFormat.RGBA_12,
349 DebayerChannelLayout.BGRA: PixelFormat.BGRA_12,
353 f
"The given input pixel format 0x{input_pixel_format.value:X} is unknown or not supported!"
Image Class for working with algorithms.
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
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 settings to their defaults.
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 current 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)
Converts a Bayer or mono image to a color image, or returns the input image unchanged.
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.