3from ids_peak_common
import PixelFormat, Interval
4from ids_peak_common.serialization
import IArchive
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.
71 @since ids_peak_icv 1.0
73 return self.__class__.__name__.replace(
"Module",
"")
79 Gets whether this module is enabled.
81 When disabled, :func:`process` returns the input image unchanged.
83 @return True if the module is enabled, False otherwise.
85 @since ids_peak_icv 1.0
93 Enables or disables the module.
95 When disabled, :func:`process` returns the input image unchanged.
97 @param enabled: True to enable, False to disable.
99 @since ids_peak_icv 1.0
108 Gets the current gamma correction exponent.
110 @return The gamma exponent currently set.
112 @since ids_peak_icv 1.0
117 def gamma(self, value: float) ->
None:
120 Sets the gamma correction exponent.
122 This value determines the degree of inverse gamma correction applied during processing,
123 where output values are computed as pow(input, 1/gamma).
124 Higher gamma values lighten the image, while values closer to zero darken it.
126 @note The gamma exponent must be within the valid range returned by gamma_range property.
128 @param value: The gamma exponent.
130 @since ids_peak_icv 1.0
140 Returns the valid range for the gamma correction exponent.
142 @return An Interval containing the minimum and maximum allowed gamma values.
144 @since ids_peak_icv 1.0
147 execute_and_map_return_codes(lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_GetGammaRange,
148 self.
_handle, ctypes.pointer(c_interval))
149 return Interval(c_interval.minimum, c_interval.maximum)
155 Whether gamma correction is enabled.
157 @return True if gamma is applied during processing.
159 @since ids_peak_icv 1.0
163 @gamma_enabled.setter
167 Whether gamma correction is enabled.
169 @param enabled: True if gamma correction is enabled.
171 @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
251 Resets all settings to their defaults.
253 Default configuration:
255 - digital_black = 0.0
257 @note The enabled state does not change when calling this function.
259 @since ids_peak_icv 1.0
266 def process(self, input_image: Image) -> Image:
269 Processes the input image and returns a tone curve corrected output image.
271 @supportedPixelformats{ToneCurveCorrection}
273 Images with other formats are passed through unmodified.
275 This operation disregards any specified image regions and processes the entire image.
277 @param input_image: The input image to be processed.
279 @return A new image with tone curve correction applied.
281 @since ids_peak_icv 1.0
292 execute_and_map_return_codes(
293 lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_ProcessInplace,
302 Serializes the object's internal state into the provided archive.
304 This function populates the given archive with all parameters required to fully represent the current state of the object.
305 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
306 in a consistent and structured format.
308 @param archive: The target archive that will store the serialized parameters.
310 @since ids_peak_icv 1.0
315 gamma_archive = archive.create_archive()
317 gamma_archive.set(
"Value", self.
_gamma)
318 archive.set(
"Gamma", gamma_archive)
320 digital_black_archive = archive.create_archive()
323 archive.set(
"DigitalBlack", digital_black_archive)
328 Restores the object's state from the provided archive.
330 This function reads and applies all necessary parameters from the given archive to reconstruct the internal state of the object.
331 It ensures that the object is restored to a valid and consistent state.
333 @param archive: The source archive containing the serialized parameters.
335 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
336 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version.
338 @note This function requires that the archive contains all expected fields as produced by a corresponding serialize() call.
340 @since ids_peak_icv 1.0
344 gamma_archive = archive.get_archive(
"Gamma")
348 digital_black_archive = archive.get_archive(
"DigitalBlack")
355 Apply gamma correction to the backend.
357 @since ids_peak_icv 1.0
359 execute_and_map_return_codes(
360 lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_SetGamma,
362 ctypes.c_float(value),
368 Apply digital black correction to the backend.
370 @since ids_peak_icv 1.0
372 execute_and_map_return_codes(
373 lib_loader.dll().peak_icv_Preprocessing_ToneCurveCorrection_SetDigitalBlack,
375 ctypes.c_float(value),
Base class for all pipeline modules.
int version(self)
Return the module version.
None _validate_version(self, IArchive archive)
bool enabled(self)
Gets whether this module is enabled.
None enabled(self, bool enabled)
Enables or disables the module.
A pipeline module for applying tone curve corrections such as gamma adjustment and digital black offs...
bool digital_black_enabled
None reset_to_default(self)
Resets all settings to their defaults.
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 _apply_digital_black(self, float value)
Apply digital black correction to the backend.
float DEFAULT_DIGITAL_BLACK
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)
Gets 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.
None enabled(self, bool enabled)
Enables or disables the module.