1from __future__
import annotations
4from typing
import TypeAlias, cast
7import numpy.typing
as npt
9from ids_peak_common
import Interval, Point
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 Enable or disable 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):
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 all module settings.
220 Restores the module configuration to its default values:
221 - hotpixel_list = empty np.ndarray of type Point
223 @since ids_peak_icv 1.0
225 execute_and_map_return_codes(
226 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_ResetList,
233 Serializes the object's internal state into the provided archive.
235 This function populates the given archive with all parameters required to fully represent the current state of the object.
236 It ensures that the object can be reconstructed or transmitted accurately by saving all relevant data members
237 in a consistent and structured format.
239 @return The serialized module's internal state.
241 @since ids_peak_icv 1.0
248 pixel_list_archives = []
250 pixel_archive = archive.create_archive()
251 pixel_archive.set(
"X", pixel.x)
252 pixel_archive.set(
"Y", pixel.y)
253 pixel_list_archives.append(pixel_archive)
254 archive.set(
"HotpixelList", pixel_list_archives)
259 Restores the object's state from the provided archive.
261 This function reads and applies all necessary parameters from the given archive to reconstruct the internal state of the object.
262 It ensures that the object is restored to a valid and consistent state.
264 @param archive: The source archive containing the serialized parameters.
266 @exception CorruptedException: If Archive is malformed, misses keys or the values are invalid
267 @exception NotSupportedException: If the 'Version' entry indicates an unsupported version.
269 @note This function requires that the archive contains all expected fields as produced by a corresponding serialize() call.
271 @since ids_peak_icv 1.0
276 pixel_archives = archive.get(
"HotpixelList", list)
278 for pixel_archive
in pixel_archives:
279 pixel_x = pixel_archive.get(
"X", int)
280 pixel_y = pixel_archive.get(
"Y", int)
281 pixel_list.append(Point(pixel_x, pixel_y))
288 if pixel_list.size == 0:
295 size = len(pixel_list)
296 c_points = create_array(peak_icv_point, size)
298 for i, pixel
in enumerate(pixel_list):
301 execute_and_map_return_codes(
302 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_SetList,
307 c_count = ctypes.c_size_t()
308 execute_and_map_return_codes(
309 lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount,
310 self.
_handle, ctypes.pointer(c_count)
313 if c_count.value == 0:
317 c_points = create_array(peak_icv_point, c_count.value)
318 execute_and_map_return_codes(lib_loader.dll().peak_icv_Preprocessing_HotpixelCorrection_GetList,
319 self.
_handle, c_points, c_count)
Thrown when an unsupported operation or feature is used.
None reset_to_default(self)
Resets the module to its default state.
None enabled(self, bool value)
Sets the enabled state of the module.
bool enabled(self)
Gets whether the module is currently enabled.
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 all module settings.
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)
Enable or disable the module.
np.ndarray|None _hotpixel_list
Base class for all pipeline modules.
None enabled(self, bool value)
Enable or disable the module.
bool enabled(self)
Get whether this module is enabled.