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

use is_dicom from pydicom and only scale dicom images if scaling is available

parent ef14b677
No related branches found
No related tags found
No related merge requests found
......@@ -251,7 +251,9 @@ def update_dcm(dcm: DICOM, image: np.ndarray) -> DICOM:
DOICOM
the updated DICOM file
"""
image, scale = scale_image(image)
if DCM_TAG_PIXEL_SCALE_FACTOR in dcm:
image, scale = scale_image(image)
dcm[DCM_TAG_PIXEL_SCALE_FACTOR].value = scale
dcm.NumberOfFrames = image.shape[0]
dcm.NumberOfSlices = image.shape[0]
......@@ -262,7 +264,6 @@ def update_dcm(dcm: DICOM, image: np.ndarray) -> DICOM:
dcm.WindowWidth = image.max()
dcm.WindowCenter = image.max() / 2
dcm.LargestImagePixelValue = image.max()
dcm[DCM_TAG_PIXEL_SCALE_FACTOR].value = scale
return dcm
......@@ -288,29 +289,6 @@ def change_uid(dcm: DICOM) -> DICOM:
return dcm
def is_dicom(filename: str) -> bool:
"""
Check if a file is a DICOM file or not.
This id done by trying to load it with `pydicom`.
Parameters
----------
filename: str
the file to be checked
Returns
-------
bool
if it is a DICOM file or not
"""
try:
pydicom.dcmread(filename, stop_before_pixels=True)
return True
except:
return False
if __name__ == "__main__":
import argparse
......
......@@ -2,9 +2,10 @@
Utility methods for dealing with different file types.
"""
import numpy as np
from pydicom.misc import is_dicom
from mu_map.file.convert import dicom_to_interfile
from mu_map.file.dicom import is_dicom, load_dcm, load_dcm_img
from mu_map.file.dicom import load_dcm, load_dcm_img
from mu_map.file.interfile import load_interfile, load_interfile_img, Interfile
......
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