forked from BATspock/TextonsSeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreconstruct_image.py
39 lines (34 loc) · 1.36 KB
/
reconstruct_image.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
import cv2
import sys
import numpy as np
np.random.seed(128)
class reconstructImage(object):
def __init__(self, feature_vector, image, number_of_centers, assignment_type=0):
'''
assignment type 'RANDOM' is suited more for higher number of clusters
assignment type 'DEFINED' is better suited when number of clusters is less than 15
however the assignemnt types do not impact the performance of the code in any significant way
'''
self.v = feature_vector
self.im = image
self.c = number_of_centers
self.type = assignment_type
def reconstruct(self):
"""
assign pixel values from the feature vectors
"""
# non zero type -> DEFINED assignement type
# else -> Random assignment
if(self.type != 1):
colors = np.random.randint(256, size=(int(self.c), 1))
else:
colors = list()
for i in range(0, 256, int(256//int(self.c))):
colors.append([i])
colors = np.array(colors)
image = np.zeros_like(self.im)
for _ in range(self.v.shape[0]):
x,y,k = self.v[_,self.v.shape[1]-3], self.v[_,self.v.shape[1]-2], self.v[_,self.v.shape[1]-1]
print(x,y,k)
image[int(x),int(y)] = colors[int(k)]
return image