Skip to content

Commit 88cde8d

Browse files
committed
add test case
1 parent fa7702c commit 88cde8d

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

slic.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def make_cluster(self, h, w):
5555
self.data[h][w][1],
5656
self.data[h][w][2])
5757

58-
def __init__(self, filename, K):
58+
def __init__(self, filename, K, M):
5959
self.K = K
60-
self.M = 40
60+
self.M = M
6161

6262
self.data = self.open_image(filename)
6363
self.image_height = self.data.shape[0]
@@ -155,13 +155,25 @@ def iterate_10times(self):
155155
self.move_clusters()
156156
for i in trange(10):
157157
self.assignment()
158-
name = 'slic_{}_assignment_M{}_K{}.png'.format(i, self.M, self.K)
159-
self.save_current_image(name)
160158
self.update_cluster()
161-
name = 'slic_{}_update_M{}_K{}.png'.format(i, self.M, self.K)
159+
name = 'lenna_M{m}_K{k}_loop{loop}.png'.format(loop=i, m=self.M, k=self.K)
162160
self.save_current_image(name)
163161

164162

165163
if __name__ == '__main__':
166-
p = SLICProcessor('Lenna.png', 200)
164+
p = SLICProcessor('Lenna.png', 200, 40)
165+
p.iterate_10times()
166+
p = SLICProcessor('Lenna.png', 300, 40)
167+
p.iterate_10times()
168+
p = SLICProcessor('Lenna.png', 500, 40)
169+
p.iterate_10times()
170+
p = SLICProcessor('Lenna.png', 1000, 40)
171+
p.iterate_10times()
172+
p = SLICProcessor('Lenna.png', 200, 5)
173+
p.iterate_10times()
174+
p = SLICProcessor('Lenna.png', 300, 5)
175+
p.iterate_10times()
176+
p = SLICProcessor('Lenna.png', 500, 5)
167177
p.iterate_10times()
178+
p = SLICProcessor('Lenna.png', 1000, 5)
179+
p.iterate_10times()

0 commit comments

Comments
 (0)