2from typing
import Union
4from ids_peak_icv
import lib_loader
8from ids_peak_ipl
import ids_peak_ipl
14 Class for applying a median filter to an image.
16 The MedianFilter class applies a median filter to reduce noise in an image. It replaces each pixel value with the
17 median value of its neighboring pixels, based on a defined kernel size.
19 @ingroup ids_peak_icv_python_filters
20 @since ids_peak_icv 1.1
26 Creates an instance of the MedianFilter class with a default kernel size of 3x3.
28 @since ids_peak_icv 1.1
36 Gets the current kernel size used for the median filter.
38 @return int: The size of the kernel.
40 @since ids_peak_icv 1.1
48 Sets the size of the kernel used for the median filter.
50 @param kernel_size: Size of the kernel. Must be an odd number greater than 1.
51 Also, it has to be smaller than the image size.
53 @since ids_peak_icv 1.1
57 def process(self, image: Union[Image, ids_peak_ipl.Image]) -> Image:
60 Applies the median filter to the given image and returns the filtered result.
62 This function processes the entire image and reduces noise using the specified kernel size.
63 The output image will have the same pixel format and dimensions as the input image.
65 @note This operation disregards any specified image regions. It processes the entire image.
67 @param image: The input image to which the median filter will be applied.
68 It can be of type Image or ids_peak_ipl.Image.
69 @return Image: The filtered image with reduced noise.
70 @exception NotSupportedException: If the input image is of an unsupported format.
71 @exception NotPossibleException: If the KernelSize is not a valid odd number greater than 1.
72 @exception OutOfRangeException: If the kernel size is bigger than the given image.
74 @since ids_peak_icv 1.1
76 _image = _check_and_get_icv_image(image)
78 output_image = Image.create_from_pixel_format_and_size(_image._pixel_format,
79 Size(_image.width, _image.height))
81 execute_and_map_return_codes(lib_loader.dll().peak_icv_Filter_Image_Median,
A size consists of width and height where width and height have to be greater than or equal to zero.