Skip to content
Snippets Groups Projects
Commit f5f73a4a authored by Tamino Huxohl's avatar Tamino Huxohl
Browse files

refactoring of dicom module

parent bdb70082
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,11 @@ from typing import Tuple ...@@ -6,7 +6,11 @@ from typing import Tuple
import numpy as np import numpy as np
import pydicom import pydicom
dcm_type = pydicom.dataset.FileDataset
"""
Alias for the main dicom datatype.
"""
DICOM = pydicom.dataset.FileDataset
""" """
Since DICOM images only allow images stored in short integer format, Since DICOM images only allow images stored in short integer format,
...@@ -58,7 +62,7 @@ class DICOMTime(Enum): ...@@ -58,7 +62,7 @@ class DICOMTime(Enum):
""" """
return f"{self.name}Time" return f"{self.name}Time"
def to_datetime(self, dicom: dcm_type) -> datetime: def to_datetime(self, dicom: DICOM) -> datetime:
""" """
Get the datetime according to this DICOMTime type. Get the datetime according to this DICOMTime type.
""" """
...@@ -94,7 +98,7 @@ def parse_age(patient_age: str) -> int: ...@@ -94,7 +98,7 @@ def parse_age(patient_age: str) -> int:
return int(_num) return int(_num)
def load_dcm(filename: str) -> Tuple[pydicom.dataset.FileDataset, np.ndarray]: def load_dcm(filename: str) -> Tuple[DICOM, np.ndarray]:
""" """
Load a DICOM image, the data as a numpy array and apply normalization of the Siemens SPECT/CT Load a DICOM image, the data as a numpy array and apply normalization of the Siemens SPECT/CT
Scanner. Scanner.
...@@ -144,9 +148,7 @@ def scale_image(image: np.ndarray, initial_scale=10000000) -> Tuple[np.ndarray, ...@@ -144,9 +148,7 @@ def scale_image(image: np.ndarray, initial_scale=10000000) -> Tuple[np.ndarray,
return image, scale return image, scale
def update_dcm( def update_dcm(dcm: DICOM, image: np.ndarray) -> DICOM:
dcm: pydicom.dataset.FileDataset, image: np.ndarray
) -> pydicom.dataset.FileDataset:
""" """
Update the image data in a DICOM file. This function scales the image, converts Update the image data in a DICOM file. This function scales the image, converts
it to unsigned integers with 16 bits and updates the pixel data in the DICOM file. it to unsigned integers with 16 bits and updates the pixel data in the DICOM file.
...@@ -176,7 +178,7 @@ def update_dcm( ...@@ -176,7 +178,7 @@ def update_dcm(
return dcm return dcm
def change_uid(dcm: pydicom.dataset.FileDataset) -> pydicom.dataset.FileDataset: def change_uid(dcm: DICOM) -> DICOM:
""" """
Change the UIDs (SeriesInstance and SOPInstance) in a DICOM header so that Change the UIDs (SeriesInstance and SOPInstance) in a DICOM header so that
it becomes its own unique file. Note that this method does not guarantee it becomes its own unique file. Note that this method does not guarantee
......
...@@ -8,22 +8,22 @@ from mu_map.file.dicom import update_dcm, change_uid ...@@ -8,22 +8,22 @@ from mu_map.file.dicom import update_dcm, change_uid
from mu_map.file.interfile import load_interfile_img from mu_map.file.interfile import load_interfile_img
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="convert an INTERFILE image to a DICOM image", description="convert an Interfile image to a DICOM image",
formatter_class=argparse.ArgumentDefaultsHelpFormatter, formatter_class=argparse.ArgumentDefaultsHelpFormatter,
) )
parser.add_argument( parser.add_argument(
"--inter", type=str, required=True, help="the INTERFILE image to be converted" "--inter", type=str, required=True, help="the Interfile image to be converted"
) )
parser.add_argument( parser.add_argument(
"--dcm", "--dcm",
type=str, type=str,
required=True, required=True,
help="a DICOM reference image - data and according fields are exchanged from the INTERFILE image", help="a DICOM reference image - data and according fields are exchanged from the Interfile image",
) )
parser.add_argument( parser.add_argument(
"--out", "--out",
type=str, type=str,
help="the output file - defaults to the INTERFILE input with a dcm extension", help="the output file - defaults to the Interfile input with a dcm extension",
) )
parser.add_argument( parser.add_argument(
"--description", "--description",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment