-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
50 lines (44 loc) · 1.48 KB
/
utils.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
44
45
46
47
48
49
50
import numpy as np
from os import getcwd, path
from cv2 import imread, IMREAD_COLOR
def read_image(path=None):
'''
Read an image from a path
Path is relative path or full path
'''
base_path = getcwd()
full_path = path.join(base_path,path)
if base_path in path:
full_path = path
if not(path.exists(full_path)):
print('The path \" {}\"does not exist. Make just that the file exist').fromat(full_path)
return None
else:
image = imread(full_path,IMREAD_COLOR)
return image
def rgb_min_image(image):
# extractes the min of the rgb values and outputs
# a gray scale image
rgb_image = np.amin(image, axis= 2)
return rgb_image
def min_filter(image):
# perfroms the min filter on 15 by 15 area
for k in range (3):
# creating a copy of the filter
i_image = image.copy()
# extracting one channel of the image
temp_image = image[:,:,k].copy()
[row,col] = temp_image.shape
# padding the iamge
temp_image = cv2.copyMakeBorder(temp_image, 14, 14, 14, 14, cv2.BORDER_REFLECT)
# perfroming the min filter with 15 x 15 window
for i in range(row):
for j in range(col):
i_image[i,j,k] = (temp_image[i:15+i,j:15+j]).min()
return i_image
def soft_matting(L,image,t_map):
image_copy = image.copy()
lamda = 10**(-4)
U = np.identity(L.shape[0])
t_map_mat = t_map*(L+lamda*U)/lamda
return t_map_mat