3from ids_peak_common
import PixelFormat, Interval
5from ids_peak_icv
import lib_loader
15 A pipeline module for applying tone curve corrections such as gamma adjustment
16 and digital black offset.
18 Both, gamma and digital black corrections can be individually enabled or disabled.
20 Default configuration:
24 @ingroup ids_peak_icv_python_pipeline_modules
25 @since ids_peak_icv 1.0
28 DEFAULT_GAMMA: float = 1.0
29 DEFAULT_DIGITAL_BLACK: float = 0.0
31 SUPPORTED_PIXEL_FORMATS = [
32 PixelFormat.MONO_8, PixelFormat.MONO_10, PixelFormat.MONO_12, PixelFormat.MONO_16, PixelFormat.RGB_8,
33 PixelFormat.RGB_10, PixelFormat.RGB_12, PixelFormat.BGR_8, PixelFormat.BGR_10, PixelFormat.BGR_12,
34 PixelFormat.RGBA_8, PixelFormat.RGBA_10, PixelFormat.RGBA_12,
35 PixelFormat.BGRA_8, PixelFormat.BGRA_10, PixelFormat.BGRA_12
41 Initialize a tone curve correction module with default settings.
43 @since ids_peak_icv 1.0
48 execute_and_map_return_codes(
49 lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_Create,
50 ctypes.pointer(handle),
60 if hasattr(self,
"_handle")
and self.
_handle:
61 lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_Destroy(self.
_handle)
67 Returns the type of the module for serialization purposes.
70 @since ids_peak_icv 1.0
72 return self.__class__.__name__.replace(
"Module",
"")
78 Get whether this module is enabled.
80 When disabled, :func:`process` returns the input image unchanged.
82 @return True if the module is enabled, False otherwise.
84 @since ids_peak_icv 1.0
92 Enable or disable the module.
94 When disabled, :func:`process` returns the input image unchanged.
96 @param value: True to enable, False to disable.
98 @since ids_peak_icv 1.0
107 Gets the current gamma correction exponent.
109 @return The gamma exponent currently set.
111 @since ids_peak_icv 1.0
116 def gamma(self, value: float) ->
None:
119 Sets the gamma correction exponent.
121 This value determines the degree of inverse gamma correction applied during processing,
122 where output values are computed as pow(input, 1/gamma).
123 Higher gamma values lighten the image, while values closer to zero darken it.
125 @note The gamma exponent must be within the valid range returned by gamma_range property.
127 @param value: The gamma exponent.
129 @since ids_peak_icv 1.0
139 Returns the valid range for the gamma correction exponent.
141 @return An Interval containing the minimum and maximum allowed gamma values.
143 @since ids_peak_icv 1.0
146 execute_and_map_return_codes(lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_GetGammaRange,
147 self.
_handle, ctypes.pointer(c_interval))
148 return Interval(c_interval.minimum, c_interval.maximum)
154 Whether gamma correction is enabled.
156 @return True if gamma is applied during processing.
158 @since ids_peak_icv 1.0
162 @gamma_enabled.setter
166 Whether gamma correction is enabled.
168 @param enabled: True if gamma correction is enabled.
170 @since ids_peak_icv 1.0
180 Gets the current digital black offset.
182 @return The digital black value currently set.
184 @since ids_peak_icv 1.0
188 @digital_black.setter
192 Sets the digital black used for digital black correction.
194 This value is subtracted from the input image channel values before gamma correction. It typically represents sensor black offset.
196 \note The digital black must be within the valid range returned by digital_black_range property.
198 @param value: The digital black value in normalized units.
200 @since ids_peak_icv 1.0
210 Returns the valid range for the digital black correction value.
212 @return An Interval containing the minimum and maximum allowed digital black values.
214 @since ids_peak_icv 1.0
217 execute_and_map_return_codes(lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_GetDigitalBlackRange,
218 self.
_handle, ctypes.pointer(c_interval))
219 return Interval(c_interval.minimum, c_interval.maximum)
225 Whether digital black correction is enabled.
227 @return True if the digital black offset is applied.
229 @since ids_peak_icv 1.0
233 @digital_black_enabled.setter
237 Whether digital black correction is enabled.
239 @param enabled: True if the digital black offset is applied.
241 @since ids_peak_icv 1.0
250 Resets all module settings.
252 Restores the module configuration to its default values:
254 - digital_black = 0.0
256 @since ids_peak_icv 1.0
263 def process(self, input_image: Image) -> Image:
266 Processes the input image and returns a tone curve corrected output image.
268 @supportedPixelformats{ToneCurveCorrection}
270 Images with other formats are passed through unmodified.
272 This operation disregards any specified image regions and processes the entire image.
274 @param input_image: The input image to be processed.
276 @return A new image with tone curve correction applied.
278 @since ids_peak_icv 1.0
289 execute_and_map_return_codes(
290 lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_ProcessInplace,
299 Serializes the object's internal state into the provided archive.
301 This function populates the given archive with all parameters required to fully represent the current state of the object.
302 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
303 in a consistent and structured format.
305 @return The serialized module's internal state.
307 @since ids_peak_icv 1.0
312 gamma_archive = archive.create_archive()
314 gamma_archive.set(
"Value", self.
_gamma)
315 archive.set(
"Gamma", gamma_archive)
317 digital_black_archive = archive.create_archive()
320 archive.set(
"DigitalBlack", digital_black_archive)
325 Restores the object's state from the provided archive.
327 This function reads and applies all necessary parameters from the given archive to reconstruct the internal state of the object.
328 It ensures that the object is restored to a valid and consistent state.
330 @param archive: The source archive containing the serialized parameters.
332 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
333 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version.
335 @note This function requires that the archive contains all expected fields as produced by a corresponding serialize() call.
337 @since ids_peak_icv 1.0
341 gamma_archive = archive.get_archive(
"Gamma")
345 digital_black_archive = archive.get_archive(
"DigitalBlack")
352 Apply gamma correction to the backend.
354 @since ids_peak_icv 1.0
356 execute_and_map_return_codes(
357 lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_SetGamma,
359 ctypes.c_float(value),
365 Apply digital black correction to the backend.
367 @since ids_peak_icv 1.0
369 execute_and_map_return_codes(
370 lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_SetDigitalBlack,
372 ctypes.c_float(value),
None enabled(self, bool value)
Sets the enabled state of the module.
bool enabled(self)
Gets whether the module is currently enabled.
Base class for all pipeline modules.
int version(self)
Return the module version.
None _validate_version(self, IArchive archive)
None enabled(self, bool value)
Enable or disable the module.
bool enabled(self)
Get whether this module is enabled.
A pipeline module for applying tone curve corrections such as gamma adjustment and digital black offs...
None reset_to_default(self)
Resets all module settings.
None digital_black_enabled(self, bool enabled)
Whether digital black correction is enabled.
None deserialize(self, IArchive archive)
Restores the object's state from the provided archive.
bool digital_black_enabled(self)
Whether digital black correction is enabled.
None gamma_enabled(self, bool enabled)
Whether gamma correction is enabled.
str type(self)
Returns the type of the module for serialization purposes.
float gamma(self)
Gets the current gamma correction exponent.
None digital_black(self, float value)
Sets the digital black used for digital black correction.
bool gamma_enabled(self)
Whether gamma correction is enabled.
None _apply_gamma(self, float value)
Apply gamma correction to the backend.
list SUPPORTED_PIXEL_FORMATS
None enabled(self, bool value)
Enable or disable the module.
None _apply_digital_black(self, float value)
Apply digital black correction to the backend.
Image process(self, Image input_image)
Processes the input image and returns a tone curve corrected output image.
None __init__(self)
Initialize a tone curve correction module with default settings.
bool enabled(self)
Get whether this module is enabled.
Interval gamma_range(self)
Returns the valid range for the gamma correction exponent.
bool _digital_black_enabled
float digital_black(self)
Gets the current digital black offset.
Interval digital_black_range(self)
Returns the valid range for the digital black correction value.
None gamma(self, float value)
Sets the gamma correction exponent.
None serialize(self, IArchive archive)
Serializes the object's internal state into the provided archive.