-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsober.py
49 lines (33 loc) · 1.31 KB
/
sober.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
import cv2
import os
from torchvision import transforms
import numpy as np
with open(os.path.join('/home/user/EGFNet/dataset', f'all.txt'), 'r') as f:
image_labels = f.readlines()
for i in range(len(image_labels)):
label_path1 = image_labels[i].strip()
imgrgb= cv2.imread('/home/user/EGFNet/dataset/seperated_images/' + label_path1 + '_rgb.png' , 0)
imgdepth = cv2.imread('/home/user/EGFNet/dataset/seperated_images/' + label_path1 + '_th.png', 0)
def tensor_to_PIL(tensor):
image = tensor.squeeze(0)
image = unloader(image)
return image
x1 = cv2.Sobel(imgrgb, cv2.CV_16S, 1, 0)
y1 = cv2.Sobel(imgrgb, cv2.CV_16S, 0, 1)
x2 = cv2.Sobel(imgdepth, cv2.CV_16S, 1, 0)
y2 = cv2.Sobel(imgdepth, cv2.CV_16S, 0, 1)
absX1 = cv2.convertScaleAbs(x1)
absY1 = cv2.convertScaleAbs(y1)
absX2 = cv2.convertScaleAbs(x2)
absY2 = cv2.convertScaleAbs(y2)
dst1 = cv2.addWeighted(absX1, 0.5, absY1, 0.5, 0)
dst2 = cv2.addWeighted(absX2, 0.5, absY2, 0.5, 0)
loader = transforms.Compose([
transforms.ToTensor()])
unloader = transforms.ToPILImage()
dst1 = loader(dst1)
dst2 = loader(dst2)
dst = (dst1 + dst2) / 255.
c = tensor_to_PIL(dst)
c = np.array(c)
cv2.imwrite('/home/user/EGFNet/dataset/edge/' + label_path1 + '.png', c)