-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
29 lines (22 loc) · 731 Bytes
/
util.py
File metadata and controls
29 lines (22 loc) · 731 Bytes
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
import cv2
import numpy as np
from matplotlib import pyplot as plt
import math
def toRGB(img):
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
def toGrayscale(img):
return cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
def toNegative(img):
return cv2.bitwise_not(img)
def toSepia(img):
sepiaImage = np.array(img, dtype=np.float64)
sepiaImage = cv2.transform(sepiaImage,
np.matrix([[0.272, 0.543, 0.131], [0.349, 0.686, 0.168], [0.393, 0.769, 0.189]]))
sepiaImage[np.where(sepiaImage > 255)] = 255
sepiaImage = np.array(sepiaImage, dtype=np.uint8)
return sepiaImage
def imageRead(path):
return cv2.imread(path)
def plotShow(img):
plt.imshow(toRGB(img))
plt.show()