From 2599a58897cbf103b0c37c6fec6ec8d4c03e5076 Mon Sep 17 00:00:00 2001 From: Valentin Vikhorev Date: Wed, 30 Apr 2025 15:51:43 +0200 Subject: [PATCH] Use np.uint8 as datatype for output nifti volumes to reduce allocations --- darwin/exporter/formats/nifti.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/darwin/exporter/formats/nifti.py b/darwin/exporter/formats/nifti.py index c23aaac48..5faaa47c1 100644 --- a/darwin/exporter/formats/nifti.py +++ b/darwin/exporter/formats/nifti.py @@ -212,7 +212,7 @@ def build_output_volumes( output_volumes[series_instance_uid] = { class_name: Volume( - pixel_array=np.zeros(volume_dims), + pixel_array=np.zeros(volume_dims, dtype=np.uint8), affine=affine, original_affine=original_affine, dims=volume_dims, @@ -460,7 +460,7 @@ def populate_output_volumes_from_raster_layer( next_global_id += 1 # Initialize multilabel volume - multilabel_volume = np.zeros(slot.metadata["shape"][1:]) + multilabel_volume = np.zeros(slot.metadata["shape"][1:], dtype=np.uint8) # Second pass: populate the multilabel volume using the global mapping for frame_idx in sorted(frames.keys()): @@ -470,7 +470,7 @@ def populate_output_volumes_from_raster_layer( mask_2d = decode_rle(dense_rle, slot.width, slot.height) # Convert the mask_2d using the global mapping - converted_mask_2d = np.zeros_like(mask_2d) + converted_mask_2d = np.zeros_like(mask_2d, dtype=np.uint8) local_mapping = frame_data.data["mask_annotation_ids_mapping"] for mask_id, local_id in local_mapping.items():