4from ids_peak_common.datatypes
import Interval, PixelFormat
5from ids_peak_common.serialization
import IArchive
6from ids_peak_common.pipeline.modules.igain_module
import IGain
7from ids_peak_icv
import lib_loader
24 Gain is an image pipeline module that applies gain correction to an image.
26 This module adjusts the intensity or color gain of an image by modifying
27 the master and per-channel (R, G, B) gain factors. It can be used to correct
28 image brightness or color balance after acquisition.
30 The gain correction is applied independently to each channel, and is typically
31 used as part of the early preprocessing stages of an image pipeline.
33 Default configuration:
39 @ingroup ids_peak_icv_python_pipeline_modules
40 @since ids_peak_icv 1.0
43 DEFAULT_MASTER: float = 1.0
46 Default master gain value.
48 @since ids_peak_icv 1.0
51 DEFAULT_RED: float = 1.0
54 Default red gain value.
56 @since ids_peak_icv 1.0
59 DEFAULT_GREEN: float = 1.0
62 Default green gain value.
64 @since ids_peak_icv 1.0
67 DEFAULT_BLUE: float = 1.0
70 Default blue gain value.
72 @since ids_peak_icv 1.0
75 SUPPORTED_PIXEL_FORMATS = [PixelFormat.BAYER_RG_8, PixelFormat.BAYER_RG_10, PixelFormat.BAYER_RG_12,
76 PixelFormat.BAYER_GR_8, PixelFormat.BAYER_GR_10, PixelFormat.BAYER_GR_12,
77 PixelFormat.BAYER_BG_8, PixelFormat.BAYER_BG_10, PixelFormat.BAYER_BG_12,
78 PixelFormat.BAYER_GB_8, PixelFormat.BAYER_GB_10, PixelFormat.BAYER_GB_12,
79 PixelFormat.MONO_8, PixelFormat.MONO_10, PixelFormat.MONO_12, PixelFormat.MONO_16]
84 Creates an instance of the gain module.
85 @since ids_peak_icv 1.0
95 execute_and_map_return_codes(
96 lib_loader.dll().peak_icv_Preprocessing_Gain_Create,
101 if getattr(self,
"_handle",
None):
102 lib_loader.dll().peak_icv_Preprocessing_Gain_Destroy(self.
_handle)
108 Returns the type of the module for serialization purposes.
112 @since ids_peak_icv 1.0
119 Resets all gain values to their default value (1.0).
121 @note The enabled state does not change when calling this function.
123 @since ids_peak_icv 1.0
139 Returns the current master gain value.
140 @since ids_peak_icv 1.0
148 Sets the master gain.
150 @param value: Gain value within the valid range returned by :py:meth:`range`.
151 @exception OutOfRangeException: If value is outside the valid range.
152 @since ids_peak_icv 1.0
155 self.
_apply(_GainType.MASTER, value)
161 Returns the current red gain value.
162 @since ids_peak_icv 1.0
167 def red(self, value: float) ->
None:
170 Sets the red channel gain.
172 @param value: Gain value within valid range.
173 @since ids_peak_icv 1.0
176 self.
_apply(_GainType.RED, value)
182 Returns the current green gain value.
183 @since ids_peak_icv 1.0
188 def green(self, value: float) ->
None:
191 Sets the green channel gain.
193 @param value: Gain value within valid range.
194 @since ids_peak_icv 1.0
197 self.
_apply(_GainType.GREEN, value)
203 Returns the current blue gain value.
204 @since ids_peak_icv 1.0
209 def blue(self, value: float) ->
None:
212 Sets the blue channel gain.
214 @param value: Gain value within valid range.
215 @since ids_peak_icv 1.0
218 self.
_apply(_GainType.BLUE, value)
224 Returns the valid range for all gain values.
226 The range applies to master and per-channel gains.
228 @return Interval representing the valid min/max gain values.
229 @since ids_peak_icv 1.0
233 execute_and_map_return_codes(
234 lib_loader.dll().peak_icv_Preprocessing_Gain_GetRange,
236 ctypes.pointer(c_interval)
238 return Interval(c_interval.minimum, c_interval.maximum)
240 def process(self, input_image: Image) -> Image:
243 Processes the input image by applying gain correction (if enabled).
245 @supportedPixelformats{Gain}
247 @param input_image: Input image to be processed.
248 @return Processed output image.
249 @since ids_peak_icv 1.0
257 input_handle = input_image._handle
258 execute_and_map_return_codes(
259 lib_loader.dll().peak_icv_Preprocessing_Gain_ProcessInplace,
268 Serializes the module’s internal state into an archive.
270 @param archive: The target archive that will store the serialized parameters.
272 @since ids_peak_icv 1.0
283 Restores the module’s state from an archive.
285 @param archive: Archive containing the serialized state.
286 @exception CorruptedException: If the archive is malformed.
287 @exception NotSupportedException: If version is unsupported.
289 @since ids_peak_icv 1.0
294 self.
redredred = archive.get(
"RedGain", float)
298 def _apply(self, gain_type: _GainType, value: float) ->
None:
299 execute_and_map_return_codes(
300 lib_loader.dll().peak_icv_Preprocessing_Gain_SetValue,
302 ctypes.c_int(gain_type.value),
303 ctypes.c_float(value),
306 def _fetch(self, gain_type: _GainType) -> float:
307 value = ctypes.c_float()
308 execute_and_map_return_codes(
309 lib_loader.dll().peak_icv_Preprocessing_Gain_GetValue,
311 ctypes.c_int(gain_type.value),
312 ctypes.pointer(value),
Gain is an image pipeline module that applies gain correction to an image.
None reset_to_default(self)
Resets all gain values to their default value (1.0).
float red(self)
Returns the current red gain value.
None deserialize(self, IArchive archive)
Restores the module’s state from an archive.
list SUPPORTED_PIXEL_FORMATS
None master(self, float value)
Sets the master gain.
float green(self)
Returns the current green gain value.
None blue(self, float value)
Sets the blue channel gain.
None _apply(self, _GainType gain_type, float value)
str type(self)
Returns the type of the module for serialization purposes.
float blue(self)
Returns the current blue gain value.
Image process(self, Image input_image)
Processes the input image by applying gain correction (if enabled).
None __init__(self)
Creates an instance of the gain module.
None red(self, float value)
Sets the red channel gain.
Interval range(self)
Returns the valid range for all gain values.
None serialize(self, IArchive archive)
Serializes the module’s internal state into an archive.
float master(self)
Returns the current master gain value.
None green(self, float value)
Sets the green channel gain.
float _fetch(self, _GainType gain_type)
Base class for all pipeline modules.