Skip to content

Commit 1b398ac

Browse files
fix(largest_k): draw needs to be done on F order arrays
1 parent c39f642 commit 1b398ac

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cc3d.pyx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,8 +1157,10 @@ def largest_k(
11571157
"""
11581158
assert k >= 0
11591159
1160+
order = "C" if img.flags.c_contiguous else "F"
1161+
11601162
if k == 0:
1161-
return np.zeros(img.shape, dtype=np.uint16)
1163+
return np.zeros(img.shape, dtype=np.uint16, order=order)
11621164
11631165
cc_labels, N = connected_components(
11641166
img, connectivity=connectivity,
@@ -1176,9 +1178,11 @@ def largest_k(
11761178
11771179
shape, dtype = cc_labels.shape, cc_labels.dtype
11781180
rns = runs(cc_labels)
1179-
del cc_labels
11801181
1181-
cc_out = np.zeros(shape, dtype=dtype)
1182+
order = "C" if cc_labels.flags.c_contiguous else "F"
1183+
del cc_labels
1184+
1185+
cc_out = np.zeros(shape, dtype=dtype, order=order)
11821186
for i, label in enumerate(preserve):
11831187
draw(i+1, rns[label], cc_out)
11841188

0 commit comments

Comments
 (0)