Skip to content

Commit 43a5861

Browse files
rm redudant broadcast
1 parent bd938e5 commit 43a5861

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/ilastik_tasks/ilastik_pixel_classification_segmentation.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,22 @@ def ilastik_pixel_classification_segmentation(
504504
)
505505

506506
# Make 3D in case of 2D data
507-
if len(new_label_img.shape) == 2:
508-
new_label_img = np.expand_dims(new_label_img, axis=0)
507+
# Check that the shape of the new label image matches the expected shape
508+
expected_shape = (
509+
e_z - s_z,
510+
e_y - s_y,
511+
e_x - s_x,
512+
)
513+
logger.info(f"Expected shape: {expected_shape}")
514+
if new_label_img.shape != expected_shape:
515+
try:
516+
new_label_img = np.broadcast_to(new_label_img, expected_shape)
517+
except Exception as err:
518+
raise ValueError(
519+
f"Shape mismatch: {new_label_img.shape} != {expected_shape} "
520+
"Between the segmented label image and expected shape in "
521+
"the zarr array."
522+
) from err
509523

510524
if output_ROI_table:
511525
bbox_df = array_to_bounding_box_table(
@@ -523,23 +537,6 @@ def ilastik_pixel_classification_segmentation(
523537
f"{len(overlap_list)} bounding-box pairs overlap"
524538
)
525539

526-
# Check that the shape of the new label image matches the expected shape
527-
expected_shape = (
528-
e_z - s_z,
529-
e_y - s_y,
530-
e_x - s_x,
531-
)
532-
logger.info(f"Expected shape: {expected_shape}")
533-
if new_label_img.shape != expected_shape:
534-
try:
535-
new_label_img = da.broadcast_to(new_label_img, expected_shape)
536-
except Exception as err:
537-
raise ValueError(
538-
f"Shape mismatch: {new_label_img.shape} != {expected_shape} "
539-
"Between the segmented label image and expected shape in "
540-
"the zarr array."
541-
) from err
542-
543540
# Compute and store 0-th level to disk
544541
da.array(new_label_img).to_zarr(
545542
url=mask_zarr,

0 commit comments

Comments
 (0)