python中实现如下任务(a) Load the image 'mandrill.jpg'. (b) Add salt&Pepper noise with different intensities (at least 3 kinds). (Tips: skimage.util.random_noise) (c) Perform smoothing linear filtering to smooth these noised images respectively. (Tips: ImageFilter.BLUR)
时间: 2023-05-21 14:02:17 浏览: 95
用Python进行图像处理
5星 · 资源好评率100%
and pepper noise to the image. (c) Apply median filter to remove the noise. (d) Display the original image and the filtered image side by side.
以下是实现该任务的 Python 代码:
```python
import cv2
# Load the image
img = cv2.imread('mandrill.jpg')
# Add salt and pepper noise
noise_img = img.copy()
cv2.randu(noise_img, 0, 255)
salt = noise_img > 250
pepper = noise_img < 5
noise_img[salt] = 255
noise_img[pepper] = 0
# Apply median filter
filtered_img = cv2.medianBlur(noise_img, 3)
# Display the images side by side
cv2.imshow('Original Image', img)
cv2.imshow('Filtered Image', filtered_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
希望这个回答能够帮到你!
阅读全文