-
Notifications
You must be signed in to change notification settings - Fork 0
/
codigo.py
97 lines (84 loc) · 2.18 KB
/
codigo.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import scipy.io as sio
import matplotlib.pyplot as plt
import imageio
import Segment
import cv2
from skimage import io, color
from sklearn.mixture import GaussianMixture as GMM
from sklearn.cluster import AgglomerativeClustering as AC
import numpy as np
from sklearn import metrics
img = 'BSDS_small/train/2092.jpg'
rgb = io.imread(img)
# plt.imshow(imageio.imread(img))
# plt.show()
# Load .mat
gt=sio.loadmat(img.replace('jpg', 'mat'))
#Load segmentation from sixth human
segm=gt['groundTruth'][0,5][0][0]['Segmentation']
print(segm.shape)
# plt.imshow(segm, cmap=plt.get_cmap('hot'))
# plt.colorbar()
# plt.show()
percent=50
scale_percent = percent # percent of original size
width = int(rgb.shape[1] * scale_percent / 100)
height = int(rgb.shape[0] * scale_percent / 100)
dim = (width, height)
resized = cv2.resize(rgb, dim, interpolation = cv2.INTER_AREA)
labels=Segment.hierarchical(3, resized)
print(labels.shape)
labels_r=labels.reshape(-1,1)
segm_r=segm.reshape(-1,1)
labels_u=np.unique(labels_r)
segm_u=np.unique(segm_r)
# for i in segm_u:
# valor=0
# count=np.zeros(len(labels_u))
# count_i=0
# for j in range(0,len(segm_r)):
# if segm_r[j]==i:
# count[labels_r[j]]+=1
# print(count)
# a=np.amax(count)/np.sum(count)
# print(a)
# segm_tr=segm_r=segm.reshape(1,-1)
# labels_tr=labels.reshape(1,-1)
# # print(metrics.adjusted_rand_score(segm_tr[0], labels_tr[0]))
# print(metrics.homogeneity_score(segm_tr[0], labels_tr[0]))
#
# print(len(segm_r))
# print(len(labels_r))
aa=segm.shape
# c=np.copy(segm)
# c.resize((int(aa[0]*0.4),int(aa[1]*0.4)))
# print(segm)
# print(c)
# print(c.shape)
# plt.imshow(segm, cmap=plt.get_cmap('hot'))
# plt.colorbar()
# plt.show()
#
#
cc=np.copy(segm)
for i in range(0,int(aa[0]/2)+1):
cc=np.delete(cc,i,0)
for i in range(0,int(aa[1]/2)+1):
cc=np.delete(cc,i,1)
print(cc)
print(cc.shape)
plt.imshow(cc, cmap=plt.get_cmap('hot'))
plt.colorbar()
plt.show()
# print(u)
if labels.shape==cc.shape :
print('si')
segm=cc
print(segm.shape)
# a=segm.resize()
# print(np.zeros(len(labels_u))[0])
# #Boundaries from third human
# segm=gt['groundTruth'][0,2][0][0]['Boundaries']
# plt.imshow(segm)
# plt.colorbar()
# plt.show()