Skip to content

Commit a4f4a84

Browse files
committed
Fix some bugs
1 parent 3ce27cf commit a4f4a84

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

slic.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def save_lab_image(path, lab_arr):
5050
io.imsave(path, rgb_arr)
5151

5252
def make_cluster(self, h, w):
53+
h = int(h)
54+
w = int(w)
5355
return Cluster(h, w,
5456
self.data[h][w][0],
5557
self.data[h][w][1],
@@ -85,9 +87,9 @@ def get_gradient(self, h, w):
8587
if h + 1 >= self.image_height:
8688
h = self.image_height - 2
8789

88-
gradient = self.data[w + 1][h + 1][0] - self.data[w][h][0] + \
89-
self.data[w + 1][h + 1][1] - self.data[w][h][1] + \
90-
self.data[w + 1][h + 1][2] - self.data[w][h][2]
90+
gradient = self.data[h + 1][w + 1][0] - self.data[h][w][0] + \
91+
self.data[h + 1][w + 1][1] - self.data[h][w][1] + \
92+
self.data[h + 1][w + 1][2] - self.data[h][w][2]
9193
return gradient
9294

9395
def move_clusters(self):
@@ -134,9 +136,9 @@ def update_cluster(self):
134136
sum_h += p[0]
135137
sum_w += p[1]
136138
number += 1
137-
_h = sum_h / number
138-
_w = sum_w / number
139-
cluster.update(_h, _w, self.data[_h][_w][0], self.data[_h][_w][1], self.data[_h][_w][2])
139+
_h = int(sum_h / number)
140+
_w = int(sum_w / number)
141+
cluster.update(_h, _w, self.data[_h][_w][0], self.data[_h][_w][1], self.data[_h][_w][2])
140142

141143
def save_current_image(self, name):
142144
image_arr = np.copy(self.data)

0 commit comments

Comments
 (0)