From f5f73a4a4786b754867bd7e0c5cd79a4b94f6035 Mon Sep 17 00:00:00 2001 From: Tamino Huxohl <thuxohl@techfak.uni-bielefeld.de> Date: Thu, 22 Dec 2022 14:57:50 +0100 Subject: [PATCH] refactoring of dicom module --- mu_map/file/dicom.py | 16 +++++++++------- mu_map/file/interfile_to_dicom.py | 8 ++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/mu_map/file/dicom.py b/mu_map/file/dicom.py index 2fed122..e3cd5ab 100644 --- a/mu_map/file/dicom.py +++ b/mu_map/file/dicom.py @@ -6,7 +6,11 @@ from typing import Tuple import numpy as np 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, @@ -58,7 +62,7 @@ class DICOMTime(Enum): """ 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. """ @@ -94,7 +98,7 @@ def parse_age(patient_age: str) -> int: 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 Scanner. @@ -144,9 +148,7 @@ def scale_image(image: np.ndarray, initial_scale=10000000) -> Tuple[np.ndarray, return image, scale -def update_dcm( - dcm: pydicom.dataset.FileDataset, image: np.ndarray -) -> pydicom.dataset.FileDataset: +def update_dcm(dcm: DICOM, image: np.ndarray) -> DICOM: """ 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. @@ -176,7 +178,7 @@ def update_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 it becomes its own unique file. Note that this method does not guarantee diff --git a/mu_map/file/interfile_to_dicom.py b/mu_map/file/interfile_to_dicom.py index b4ce0b1..830d49b 100644 --- a/mu_map/file/interfile_to_dicom.py +++ b/mu_map/file/interfile_to_dicom.py @@ -8,22 +8,22 @@ from mu_map.file.dicom import update_dcm, change_uid from mu_map.file.interfile import load_interfile_img 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, ) 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( "--dcm", type=str, 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( "--out", 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( "--description", -- GitLab