IDS peak ICV v1.2.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
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 @algorithm.setter
122 def algorithm(self, algorithm: ToneMappingAlgorithm) -> None:
123 """!
124 @brief
125 Sets the tone mapping algorithm.
126
127 @param algorithm:
128 The tone mapping algorithm to use.
129
130 @since ids_peak_icv 1.2
131 """
132 execute_and_map_return_codes(
133 lib_loader.dll().peak_icv_ToneMapping_SetAlgorithm,
134 self._handle,
135 ctypes.c_int(algorithm.value),
136 )
137
138 def process(self, image: Image) -> Image:
139 """!
140 @brief
141 Applies tone mapping to an HDR image.
142
143 Processes the provided HDR image and converts it into a displayable
144 Low Dynamic Range (LDR) image using the tone mapping algorithm
145 associated with this object.
146
147 The input image must be compatible with the tone mapping configuration.
148
149 @param image:
150 The HDR image to be tone mapped.
151
152 @return
153 The resulting tone-mapped image.
154
155 @since ids_peak_icv 1.2
156 """
157 _check_icv_image(image)
158
159 # Query the output pixel format from the backend
160 output_pixel_format = ctypes.c_int()
161 execute_and_map_return_codes(
162 lib_loader.dll().peak_icv_ToneMapping_Process_GetOutputPixelFormat,
163 self._handle,
164 ctypes.c_int(image.pixel_format.value),
165 ctypes.pointer(output_pixel_format),
166 )
167
168 # Create output image with same size and backend-defined pixel format
169 output_image = Image.create_from_pixel_format_and_size(
170 PixelFormat(output_pixel_format.value),
171 Size(image.width, image.height),
172 )
173
174 # Perform tone mapping
175 execute_and_map_return_codes(
176 lib_loader.dll().peak_icv_ToneMapping_Process,
177 self._handle,
178 image._handle,
179 output_image._handle,
180 )
181
182 return output_image
A size consists of width and height where width and height have to be greater than or equal to zero.
Definition size.py:9
Enum listing all supported pixel formats and their internal IDs.
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.