平滑
原始图像:
h1
h2
锐化
原始图像:
h3
h4
h5
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
ifd1 = 'input.jpg' # dayanta
ofd = 'output.jpg'
def read_gray_img(fd):
img = cv.imread(fd)
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
return img
def add_noise(img):
res = np.copy(img)
row, col = res.shape
for i in range(5000):
x = np.random.randint(0, row)
y = np.random.randint(0, col)
res[x, y] = 255
return res
def box_filter(img):
res = cv.boxFilter(img, -1, (3,3), normalize=1)
cv.imwrite('output.jpg', res)
def gaussian_filter(img):
res = cv.GaussianBlur(img, (3,3), 0)
cv.imwrite('output.jpg', res)
def l