sharp.py
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import cv2
import numpy as np
from PIL import Image
from PIL import ImageFilter
img= cv2.imread('Lenna.png')
cv2.imshow('Original',img)
output = img
"""
#Blur_gaussian
output = cv2.GaussianBlur(img,(5,5),1)
cv2.imshow('BlurGaussian',output)
cv2.imwrite('BlurGaussian.png',output)
"""
"""
#Blur
size = 3
kernel_motion_blur = np.zeros((size,size))
kernel_motion_blur[int((size-1)/2),:] = np.ones(size)
kernel_motion_blur = kernel_motion_blur / size
output = cv2.filter2D(img,-1,kernel_motion_blur)
cv2.imshow('Blur',output)
cv2.imwrite('Blur.png',output)
"""
#Sharpening
kernel_sharpen_1 = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]])
#kernel_sharpen_2 = np.array([[1,1,1],[1,-7,1],[1,1,1]])
#kernel_sharpen_3 = np.array([[-1,-1,-1,-1,-1],[-1,2,2,2,-1],[-1,2,8,2,-1],[-1,2,2,2,-1],[-1,-1,-1,-1,-1]])/8.0
output_1 = cv2.filter2D(output,-1,kernel_sharpen_1)
#output_2 = cv2.filter2D(img,-1,kernel_sharpen_2)
#output_3 = cv2.filter2D(img,-1,kernel_sharpen_3)
cv2.imshow('Sharpening',output_1)
#cv2.imshow('Excessive Sharpening',output_2)
#cv2.imshow('Edge Enhancement',output_3)
cv2.imwrite('Sharpening.png',output_1)
img = cv2.imread('input2.png')
img_yuv = cv2.cvtColor(output_1, cv2.COLOR_BGR2YUV)
img_yuv[:,:,0] = cv2.equalizeHist(img_yuv[:,:,0])
img_output = cv2.cvtColor(img_yuv,cv2.COLOR_YUV2BGR)
cv2.imshow('histogram_equalization',img_output)
cv2.imwrite('histogram_equalization.png',img_output)
cv2.waitKey()