1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| def im_sharpen_krisch(label, path): img = cv2.imread(path) nimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) height, width, channels = img.shape filtered_list = np.zeros((8, height, width)) kernel = [np.array([[5, 5, 5], [-3, 0, -3], [-3, -3, -3]]), np.array([[-3, 5, 5], [-3, 0, 5], [-3, -3, -3]]), np.array([[-3, -3, 5], [-3, 0, 5], [-3, -3, 5]]), np.array([[-3, -3, -3], [-3, 0, 5], [-3, 5, 5]]), np.array([[-3, -3, -3], [-3, 0, -3], [5, 5, 5]]), np.array([[-3, -3, -3], [5, 0, -3], [5, 5, -3]]), np.array([[5, -3, -3], [5, 0, -3], [5, -3, -3]]), np.array([[5, 5, -3], [5, 0, -3], [-3, -3, -3]])]
for i in range(8): out = cv2.filter2D(nimg, cv2.CV_16S, kernel[i]) filtered_list[i] = out
final = np.max(filtered_list, axis=0) final[np.where(final >= 255)] = 255 final[np.where(final < 255)] = 0 final = final.astype(np.uint8)
path = save_file(final, path, 'sharpenkrisch') to_label_gray(label, final)
return path
|