이미 medianblur를 사용했음.
2019/12/10 - [Study/DAFIT] - 09 OpenCV 연습하기(1) - 04 Noise and Filtering(1)
그냥 blur와의 차이를 확인해보자.
import numpy as np
import cv2
from random import random
from google.colab.patches import cv2_imshow
import copy
img_path = '/content/drive/My Drive/다핏문제/909/lena.jpg'
def salt_and_pepper(image, p):
output = np.zeros(image.shape,np.uint8)
thres = 1 - p
for i in range(image.shape[0]):
for j in range(image.shape[1]):
rdn = random()
if rdn < p:
output[i][j] = 0
elif rdn > thres:
output[i][j] = 255
else:
output[i][j] = image[i][j]
return output
img = cv2.imread(img_path,2)
origin = copy.deepcopy(img)
sapimg = salt_and_pepper(img,0.2)
cv2_imshow(sapimg)
img = cv2.blur(sapimg, (3,3))
cv2_imshow(img)
img = cv2.medianBlur(sapimg, 3) #salt and pepper 제거 효과적
cv2_imshow(img)
확실히 medianBlur가 salt and pepper 노이즈 처리가 잘된다.
'DAFIT > 909 - OpenCV 연습하기 (1)' 카테고리의 다른 글
<DAFIT> 09 OpenCV 연습하기(1) - 07 Edge Detection(2) (0) | 2019.12.11 |
---|---|
<DAFIT> 09 OpenCV 연습하기(1) - 06 Edge Detection(1) (0) | 2019.12.11 |
<DAFIT> 09 OpenCV 연습하기(1) - 04 Noise and Filtering(1) (0) | 2019.12.10 |
<DAFIT> 09 OpenCV 연습하기(1) - 03 Sharpening Filter (0) | 2019.12.10 |
<DAFIT> 09 OpenCV 연습하기(1) - 02 Blurring Filter (0) | 2019.12.10 |