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

remove load_dcm_img function from dataset utils

parent 4bf37715
No related branches found
No related tags found
No related merge requests found
from typing import Tuple
import numpy as np
import pydicom
"""
Since DICOM images only allow images stored in short integer format,
the Siemens scanner software multiplies values by a factor before storing
so that no precision is lost.
The scale can be found in this private DICOM tag.
"""
DCM_TAG_PIXEL_SCALE_FACTOR = 0x00331038
def load_dcm_img(filename: str) -> np.ndarray:
"""
Load a DICOM image as a numpy array and apply normalization of the Siemens SPECT/CT
Scanner.
:param filename: filename of the DICOM image
:return: the image scaled and loaded into a numpy array
"""
image = pydicom.dcmread(filename)
image = image.pixel_array / image[DCM_TAG_PIXEL_SCALE_FACTOR].value
return image
def align_images(
......@@ -31,9 +9,17 @@ def align_images(
"""
Center align the image with more slices to the one with fewer slices on the first axis (z-axis).
:param image_1: the image to be aligned
:param image_2: the image to which image_1 is aligned
:return: both images aligned in the order they were put in
Parameters
----------
image_1: np.ndarray
the image to be aligned
image_2: np.ndarray
the image to which image_1 is aligned
Returns
-------
Tuple[np.ndarray, np.ndarray]
both images aligned in the order they were put in
"""
# reverse function if image_2 has more slices
if image_2.shape[0] > image_1.shape[0]:
......
......@@ -3,7 +3,8 @@ import matplotlib.pyplot as plt
import numpy as np
import pydicom
from mu_map.dataset.util import load_dcm_img, align_images
from mu_map.dataset.util import align_images
from mu_map.file.dicom import load_dcm_img
from mu_map.util import to_grayscale
mu_map = load_dcm_img("./data/second/images/0085-stress-mu_map.dcm")
......
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