OpenCV 边缘检测之图像增强
图像增强代码示例:
import cv2
filename = C:\Users\username\Desktop\opencv
img = cv2.imread(filname + 'picture.jpg',0)
row, column = img.shape
img_f = np.copy(img)
gradient = np.zeros((row,column))
img = img.astype('float')
for x in range(row - 1):
for y in range(column - 1):
gx = abs(img[x + 1, y] - img[x, y])
gy = abs(img[x, y + 1] - img[x, y])
gradient[x, y] = gx + gy
share = img_f + gradient
sharp = np.where(sharp > 255, 255, sharp)
sharp = np.where(sharp < 0, 0, sharp)
gradient = gradient.astype('uint8')
sharp = sharp.astype('uint8')
filepath = C:\Users\username\Desktop\opencv
cv2.imwrite(filepath + 'out/gradient.png', gradient)
|