1from __future__
import annotations
4from typing
import TypeAlias, cast
7import numpy.typing
as npt
9from ids_peak_common
import Interval, Point
11from ids_peak_common.serialization
import IArchive
12from ids_peak_icv
import lib_loader
20PointArray: TypeAlias = npt.NDArray[np.object_]
26 Hotpixel correction is an image pipeline module for detecting and correcting hot pixels in camera images.
28 Provides the feature HotpixelCorrectionFeature.
30 @since ids_peak_icv 1.0
33 DEFAULT_HOTPIXEL_LIST: np.ndarray = np.empty(0, dtype=Point)
36 Default hotpixel list (empty list).
38 @since ids_peak_icv 1.0
44 Creates a HotpixelCorrectionModule module with default settings (no correction).
46 @since ids_peak_icv 1.0
54 execute_and_map_return_codes(
55 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_Create,
56 ctypes.pointer(_hotpixel_correction_handle)
58 self.
_handle = _hotpixel_correction_handle
64 Returns the type of the module for serialization purposes.
68 @since ids_peak_icv 1.0
70 return "HotpixelCorrection"
76 Gets whether this module is enabled.
78 When disabled, :func:`process` returns the input image unchanged.
80 @return True if the module is enabled, False otherwise.
82 @since ids_peak_icv 1.0
90 Enables or disables the module.
92 When disabled, :func:`process` returns the input image unchanged.
94 @param enabled: True to enable, False to disable.
96 @since ids_peak_icv 1.0
105 Gets the current array of known hot pixels.
107 @return An array containing the positions of all configured hot pixels.
109 @since ids_peak_icv 1.0
118 @hotpixel_list.setter
122 Sets the array of known hot pixels.
124 @param pixel_list: An array of hot pixel positions to use.
126 @since ids_peak_icv 1.0
128 if not isinstance(pixel_list, np.ndarray):
129 raise NotSupportedException(
130 "Parameter points has to be a numpy array of Point objects.")
132 if pixel_list.size == 0:
141 Gets the valid range for sensitivity.
143 @return The valid sensitivity range.
145 @since ids_peak_icv 1.0
148 execute_and_map_return_codes(
149 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange,
150 self.
_handle, ctypes.pointer(c_interval))
151 return Interval(c_interval.minimum, c_interval.maximum)
153 def detect(self, image: Image, sensitivity: int = 3, gain_factor: float = 1.0) ->
None:
156 Performs immediate hot pixel detection on the given image.
158 This method analyzes the provided image and detects hot pixels based on the
159 sensitivity setting. The results are stored internally and can be accessed using pixel_list.
161 Note: Calling this function will overwrite any existing hot pixel list previously set via pixel_list.
163 @param image: The input image to analyze for hot pixel detection.
164 @param sensitivity: Sensitivity for hot pixel detection. A higher sensitivity
165 may result in detecting more hot pixels, including possible
167 @param gain_factor: Gain factor applied to the image. Used to account for
168 increased noise levels when detecting hot pixels.
170 @exception NotSupportedException: If image has any other than the supported pixel formats.
172 @since ids_peak_icv 1.0
174 execute_and_map_return_codes(
175 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_Detect,
176 self.
_handle, image._handle, ctypes.c_size_t(sensitivity), ctypes.c_float(gain_factor))
179 def process(self, input_image: Image) -> Image:
182 Applies hot pixel correction to the input image in place and returns a reference to the modified image.
184 @supportedPixelformats{HotpixelCorrection}
186 The correction is performed based on the current configuration of the module. The operation modifies the
187 input image directly and does not create a copy.
189 @supportedPixelformats{HotpixelCorrection}
191 Images with other formats are passed through unmodified.
193 This operation disregards any specified image regions and processes the entire image.
195 @param input_image: The input image to be processed and corrected.
197 @exception NotSupportedException: If image has any other than the supported pixel formats.
199 @return A new image with hotpixel correction applied.
201 @since ids_peak_icv 1.0
209 execute_and_map_return_codes(
210 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace,
211 self.
_handle, input_image._handle)
218 Resets the hotpixel list to its default value (empty list).
220 @note The enabled state does not change when calling this function.
222 @since ids_peak_icv 1.0
224 execute_and_map_return_codes(
225 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_ResetList,
232 Serializes the object's internal state into the provided archive.
234 This function populates the given archive with all parameters required to fully represent the current state of the object.
235 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
236 in a consistent and structured format.
238 @param archive: The target archive that will store the serialized parameters.
240 @since ids_peak_icv 1.0
247 pixel_list_archives = []
249 pixel_archive = archive.create_archive()
250 pixel_archive.set(
"X", pixel.x)
251 pixel_archive.set(
"Y", pixel.y)
252 pixel_list_archives.append(pixel_archive)
253 archive.set(
"HotpixelList", pixel_list_archives)
258 Restores the object's state from the provided archive.
260 This function reads and applies all necessary parameters from the given archive to reconstruct the internal state of the object.
261 It ensures that the object is restored to a valid and consistent state.
263 @param archive: The source archive containing the serialized parameters.
265 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
266 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version.
268 @note This function requires that the archive contains all expected fields as produced by a corresponding serialize() call.
270 @since ids_peak_icv 1.0
275 pixel_archives = archive.get(
"HotpixelList", list)
277 for pixel_archive
in pixel_archives:
278 pixel_x = pixel_archive.get(
"X", int)
279 pixel_y = pixel_archive.get(
"Y", int)
280 pixel_list.append(Point(pixel_x, pixel_y))
287 if pixel_list.size == 0:
294 size = len(pixel_list)
295 c_points = create_array(peak_icv_point, size)
297 for i, pixel
in enumerate(pixel_list):
300 execute_and_map_return_codes(
301 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_SetList,
306 c_count = ctypes.c_size_t()
307 execute_and_map_return_codes(
308 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount,
309 self.
_handle, ctypes.pointer(c_count)
312 if c_count.value == 0:
316 c_points = create_array(peak_icv_point, c_count.value)
317 execute_and_map_return_codes(lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_GetList,
318 self.
_handle, c_points, c_count)
Hotpixel correction is an image pipeline module for detecting and correcting hot pixels in camera ima...
bool _hotpixel_correction_enabled
None reset_to_default(self)
Resets the hotpixel list to its default value (empty list).
None _apply_pixel_list(self)
None deserialize(self, IArchive archive)
Restores the object's state from the provided archive.
PointArray hotpixel_list(self)
Gets the current array of known hot pixels.
None hotpixel_list(self, PointArray pixel_list)
Sets the array of known hot pixels.
str type(self)
Returns the type of the module for serialization purposes.
None detect(self, Image image, int sensitivity=3, float gain_factor=1.0)
Performs immediate hot pixel detection on the given image.
None _call_backend_set_list(self, npt.NDArray pixel_list)
Image process(self, Image input_image)
Applies hot pixel correction to the input image in place and returns a reference to the modified imag...
None __init__(self)
Creates a HotpixelCorrectionModule module with default settings (no correction).
bool enabled(self)
Gets whether this module is enabled.
None _call_backend_get_list(self)
None serialize(self, IArchive archive)
Serializes the object's internal state into the provided archive.
Interval sensitivity_range(self)
Gets the valid range for sensitivity.
None enabled(self, bool enabled)
Enables or disables the module.
np.ndarray|None _hotpixel_list
Base class for all pipeline modules.
bool enabled(self)
Gets whether this module is enabled.
None enabled(self, bool enabled)
Enables or disables the module.