Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DICOMSeriesToVolumeOperator Slice Removal Fix #527

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions monai/deploy/operators/dicom_series_to_volume_operator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021-2023 MONAI Consortium
# Copyright 2021-2025 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -234,11 +234,17 @@
series._sop_instances[slice_index].distance = distance
series._sop_instances[slice_index].first_pixel_on_slice_normal = point
else:
print("going to removing slice ", slice_index)
logging.debug(f"Slice index to remove: {slice_index}")

Check warning on line 237 in monai/deploy/operators/dicom_series_to_volume_operator.py

View check run for this annotation

Codecov / codecov/patch

monai/deploy/operators/dicom_series_to_volume_operator.py#L237

Added line #L237 was not covered by tests
slice_indices_to_be_removed.append(slice_index)

for sl_index, _ in enumerate(slice_indices_to_be_removed):
logging.debug(f"Total slices before removal (if applicable): {len(series._sop_instances)}")

Check warning on line 240 in monai/deploy/operators/dicom_series_to_volume_operator.py

View check run for this annotation

Codecov / codecov/patch

monai/deploy/operators/dicom_series_to_volume_operator.py#L240

Added line #L240 was not covered by tests

# iterate in reverse order to avoid affecting subsequent indices after a deletion
for sl_index in sorted(slice_indices_to_be_removed, reverse=True):

Check warning on line 243 in monai/deploy/operators/dicom_series_to_volume_operator.py

View check run for this annotation

Codecov / codecov/patch

monai/deploy/operators/dicom_series_to_volume_operator.py#L243

Added line #L243 was not covered by tests
del series._sop_instances[sl_index]
logging.info(f"Removed slice index: {sl_index}")

Check warning on line 245 in monai/deploy/operators/dicom_series_to_volume_operator.py

View check run for this annotation

Codecov / codecov/patch

monai/deploy/operators/dicom_series_to_volume_operator.py#L245

Added line #L245 was not covered by tests

logging.debug(f"Total slices after removal (if applicable): {len(series._sop_instances)}")

Check warning on line 247 in monai/deploy/operators/dicom_series_to_volume_operator.py

View check run for this annotation

Codecov / codecov/patch

monai/deploy/operators/dicom_series_to_volume_operator.py#L247

Added line #L247 was not covered by tests

series._sop_instances = sorted(series._sop_instances, key=lambda s: s.distance)
series.depth_direction_cosine = copy.deepcopy(last_slice_normal)
Expand Down