cv2.medianBlur
时间: 2023-10-26 17:34:28 浏览: 95
cv2.medianBlur() is a function in OpenCV library used to apply median filtering to an image. Median filtering is a non-linear filtering technique where each pixel value is replaced by the median value of its neighboring pixels. This technique is useful in removing salt and pepper noise from an image while preserving the edges and details.
Syntax:
cv2.medianBlur(src, ksize[, dst])
Parameters:
src: Input image.
ksize: The size of the kernel used for median filtering.
dst: Output image, of the same size and type as src.
Return Value:
The function returns the median-filtered image.
Example:
import cv2
import numpy as np
# Load image
img = cv2.imread("image.jpg")
# Apply median filtering
median = cv2.medianBlur(img, 5)
# Display result
cv2.imshow("Original Image", img)
cv2.imshow("Median Filtering", median)
cv2.waitKey(0)
cv2.destroyAllWindows()
阅读全文