Skip to content

Commit 305b6e7

Browse files
committed
slic torch2
1 parent a544b4e commit 305b6e7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

slic_torch2.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def unflatten(t):
222222
normalized_X_nearest_clusters = unflatten(normalized_X_nearest_clusters)
223223
#Y_nearest_clusters = torch.permute(Y_nearest_clusters.view(concat_features.shape[0],concat_features.shape[2],concat_features.shape[3],1),(0,3,1,2))
224224
#X_nearest_clusters = torch.permute(X_nearest_clusters.view(concat_features.shape[0],concat_features.shape[2],concat_features.shape[3],1),(0,3,1,2))
225+
p46()
225226
Ymin = (self.Y - 2*self.S).clamp(0,None)
226227
Ymax = (self.Y + 2*self.S).clamp(None,self.image_height)
227228

@@ -305,11 +306,19 @@ def assignment(self):
305306
#------------------------------------------------------
306307
cluster_y,cluster_x = (self.image_height-1)* (cluster[0]*self.norm_spat_std[0]),(self.image_width-1)* (cluster[1]*self.norm_spat_std[1])
307308

308-
top = (self.image_height-1)* (cluster[0]*self.norm_spat_std[0]) - 2 * self.S
309-
bottom = (self.image_height-1)* (cluster[0] *self.norm_spat_std[0]) + 2 * self.S
310-
left = (self.image_width-1)* (cluster[1] *self.norm_spat_std[1])- 2 * self.S
311-
right = (self.image_width-1)* (cluster[1]*self.norm_spat_std[1]) + 2 * self.S
309+
#TODO: should this not be self.S//2
310+
#...................................
311+
#half_window_height = 2 * self.S
312+
#half_window_width = 2 * self.S
313+
half_window_height = self.S/2
314+
half_window_width = self.S/2
315+
#...................................
316+
top = (self.image_height-1)* (cluster[0]*self.norm_spat_std[0]) - half_window_height
317+
bottom = (self.image_height-1)* (cluster[0] *self.norm_spat_std[0]) + half_window_height
318+
left = (self.image_width-1)* (cluster[1] *self.norm_spat_std[1])- half_window_width
319+
right = (self.image_width-1)* (cluster[1]*self.norm_spat_std[1]) + half_window_width
312320
top = max( top,0)
321+
#TODO: image_height - 1?
313322
bottom = min(bottom,self.image_height)
314323
left = max(left,0)
315324
right = min(right,self.image_width)

0 commit comments

Comments
 (0)