-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpOps.py
43 lines (36 loc) · 1.34 KB
/
pOps.py
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
from hashlib import new
import numpy as np
import cv2 as cv
# all the point operations that can be performed on an image are defined here
def invert(img: np.array, channel: int):
if channel == 3:
img[:,:,0] = 255 - img[:,:,0]
img[:,:,1] = 255 - img[:,:,1]
img[:,:,2] = 255 - img[:,:,2]
else:
img = 255 - img
return img
def auto_contrast(img: np.array, channel: int):
if channel == 3:
img[:,:,0] = img[:,:,0] - np.min(img[:,:,0]) * (255)/(np.max(img[:,:,0]) - np.min(img[:,:,0]))
img[:,:,1] = img[:,:,1] - np.min(img[:,:,1]) * (255)/(np.max(img[:,:,1]) - np.min(img[:,:,1]))
img[:,:,2] = img[:,:,2] - np.min(img[:,:,2]) * (255)/(np.max(img[:,:,2]) - np.min(img[:,:,2]))
else:
img = img - np.min(img) * (255)/(np.max(img) - np.min(img))
return img
def threshold(img: np.array, t_point: int):
img[img >= t_point] = 255
img[img < t_point] = 0
return img
def equalize(img: np.array, channel: int):
if channel == 3:
img[:,:,0] = cv.equalizeHist(img[:,:,0])
img[:,:,1] = cv.equalizeHist(img[:,:,1])
img[:,:,2] = cv.equalizeHist(img[:,:,2])
else:
img = cv.equalizeHist(img)
return img
def clipping(img: np.array, r1: int, r2: int):
img[(img >= r1) & (img <= r2)] = 255
img[(img < r1) & (img > r2)] = 0
return img