IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
tone_mapping.py
Go to the documentation of this file.
1from __future__ import annotations
2
3import ctypes
4from enum import Enum
5from typing import Any
6
7from ids_peak_icv import lib_loader
9 peak_icv_tone_mapping_handle,
10 peak_icv_image_handle,
11)
12from ids_peak_icv.backend.utils import execute_and_map_return_codes
13from ids_peak_icv.datatypes.image import Image, _check_icv_image
14from ids_peak_common.datatypes.pixelformat import PixelFormat
15from ids_peak_common.datatypes.geometry.size import Size
16
17
19 """!
20 @brief
21 Specifies the tone mapping algorithm.
22
23 Defines the algorithm used to map a High Dynamic Range (HDR) image to a
24 displayable Low Dynamic Range (LDR) image.
25
26 @note
27 Currently, only the Reinhard tone mapping algorithm is supported.
28 Additional tone mapping algorithms may be added in future versions.
29
30 @ingroup ids_peak_icv_python_hdr
31 @since ids_peak_icv 1.2
32 """
33
34 REINHARD = 0
35 """!
36 @brief
37 Reinhard tone mapping operator.
38
39 Applies a global tone mapping operator based on the method proposed
40 by Reinhard et al. to compress the dynamic range of an HDR image while
41 preserving visual contrast.
42 """
43
44
46 """!
47 @brief
48 Performs tone mapping on HDR images.
49
50 This class provides functionality to convert a High Dynamic Range (HDR)
51 image into a displayable Low Dynamic Range (LDR) image using a tone
52 mapping algorithm.
53
54 Internally, tone mapping is performed using the Reinhard tone mapping
55 operator, which is currently the only supported algorithm. The algorithm
56 is fixed at object creation time.
57
58 ### Typical usage
59 - Create a :class:`ToneMapping` object
60 - Optionally query or set the tone mapping algorithm
61 - Call :meth:`process` to convert an HDR image into an LDR image
62
63 ### Limitations
64 - The input image must be a valid HDR image.
65 - Only the Reinhard tone mapping algorithm is currently supported.
66
67 @ingroup ids_peak_icv_python_hdr
68 @since ids_peak_icv 1.2
69 """
70
71 def __init__(self, *args: Any, **kwargs: Any) -> None:
72 """!
73 @brief
74 Constructs a tone mapping object.
75
76 Creates and initializes a tone mapping object using the default
77 tone mapping algorithm (Reinhard).
78
79 @since ids_peak_icv 1.2
80 """
82 execute_and_map_return_codes(
83 lib_loader.dll().peak_icv_ToneMapping_Create,
84 ctypes.pointer(self._handle),
85 )
86
87 def __del__(self) -> None:
88 """!
89 @brief
90 Destroys the tone mapping object.
91
92 Releases all resources associated with the tone mapping object.
93
94 @since ids_peak_icv 1.2
95 """
96 if hasattr(self, "_handle") and self._handle:
97 lib_loader.dll().peak_icv_ToneMapping_Destroy(self._handle)
98
99 @property
100 def algorithm(self) -> ToneMappingAlgorithm:
101 """!
102 @brief
103 Returns the tone mapping algorithm used by this object.
104
105 The algorithm is defined at construction time and determines how
106 the input HDR image is converted into a displayable image.
107
108 @return
109 The tone mapping algorithm identifier.
110
111 @since ids_peak_icv 1.2
112 """
113 algorithm = ctypes.c_int()
114 execute_and_map_return_codes(
115 lib_loader.dll().peak_icv_ToneMapping_GetAlgorithm,
116 self._handle,
117 ctypes.pointer(algorithm),
118 )
119 return ToneMappingAlgorithm(algorithm.value)
120
121 def process(self, image: Image) -> Image:
122 """!
123 @brief
124 Applies tone mapping to an HDR image.
125
126 Processes the provided HDR image and converts it into a displayable
127 Low Dynamic Range (LDR) image using the tone mapping algorithm
128 associated with this object.
129
130 The input image must be compatible with the tone mapping configuration.
131
132 @supportedPixelformats{ToneMapping}
133
134 @param image:
135 The HDR image to be tone mapped.
136
137 @return
138 The resulting tone mapped image with pixel format Mono8 resp. RGB8.
139
140 @since ids_peak_icv 1.2
141 """
142 _check_icv_image(image)
143
144 # Query the output pixel format from the backend
145 output_pixel_format = ctypes.c_int()
146 execute_and_map_return_codes(
147 lib_loader.dll().peak_icv_ToneMapping_Process_GetOutputPixelFormat,
148 self._handle,
149 ctypes.c_int(image.pixel_format.value),
150 ctypes.pointer(output_pixel_format),
151 )
152
153 # Create output image with same size and backend-defined pixel format
154 output_image = Image.create_from_pixel_format_and_size(
155 PixelFormat(output_pixel_format.value),
156 Size(image.width, image.height),
157 )
158
159 # Perform tone mapping
160 execute_and_map_return_codes(
161 lib_loader.dll().peak_icv_ToneMapping_Process,
162 self._handle,
163 image._handle,
164 output_image._handle,
165 )
166
167 return output_image
None __init__(self, *Any args, **Any kwargs)
Constructs a tone mapping object.
Image process(self, Image image)
Applies tone mapping to an HDR image.
None __del__(self)
Destroys the tone mapping object.
ToneMappingAlgorithm algorithm(self)
Returns the tone mapping algorithm used by this object.