-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SimpleITK] Use SimpleITK to generate NifTI files with correct pixel …
…spacing (#6) - Uses the SimpleITK library and the DICOM data elements ImagePositionPatient and PixelSpacing to convert a raw pixel array into a NifTI file with the correct spacing - Updates the package version to 0.0.2.
1 parent
7089497
commit 72bfbd2
Showing
6 changed files
with
88 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Utility methods for image processing.""" | ||
|
||
import logging | ||
|
||
|
||
from typing import Dict, Tuple | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def compute_z_dim_pixel_spacing( | ||
image_position_patient: Dict[int, Tuple[float, float, float]] | ||
) -> float: | ||
"""Computes the z dimension pixel spacing value from the Image Position (Patient) DICOM tag.""" | ||
instance_indices = image_position_patient.keys() | ||
first_instance_index = min(instance_indices) | ||
last_instance_index = max(instance_indices) | ||
first_z_position = image_position_patient[first_instance_index][2] | ||
last_z_position = image_position_patient[last_instance_index][2] | ||
|
||
# Warn if there are missing instances. | ||
num_expected_instances = last_instance_index - first_instance_index + 1 | ||
num_actual_instances = len(instance_indices) | ||
if num_actual_instances != num_expected_instances: | ||
logger.warning( | ||
'Expected %s instances, but received %s instead.', | ||
num_expected_instances, | ||
num_actual_instances | ||
) | ||
return abs(last_z_position - first_z_position) / (last_instance_index - first_instance_index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters