Skip to content

Commit d3c47d9

Browse files
committed
Fix pydicom support by replacing dicomio with dcmread for reading DICOM files
1 parent 99b98ab commit d3c47d9

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Supported versions of Python have been updated (drop support for Python 3.8, add
1717
* The `info_callback` is a function that takes the annotation object and returns a string with the information to display
1818
* Default `info_callback` is redirected to the `get_infos` method of the annotation object (this makes the feature backward compatible)
1919

20+
🛠️ Bug fixes:
21+
22+
* Fixed `pydicom` support: use `dcmread` instead of `read_file` to read DICOM files
23+
2024
## Version 2.6.3 ##
2125

2226
🧯 In this release, test coverage is 79%.

plotpy/builder/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ def image(
226226
if isinstance(filename, str) and filename.lower().endswith(".dcm"):
227227
# pylint: disable=import-outside-toplevel
228228
# pylint: disable=import-error
229-
from pydicom import dicomio # type:ignore
229+
from pydicom import dcmread # type:ignore
230230

231-
template = dicomio.read_file(filename, stop_before_pixels=True, force=True)
231+
template = dcmread(filename, stop_before_pixels=True, force=True)
232232
ipp = getattr(template, "ImagePositionPatient", ["0", "0", "0"])
233233
pxs = getattr(template, "PixelSpacing", ["1", "1"])
234234
ipx, ipy = float(ipp[0]), float(ipp[1])

plotpy/io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def _import_dcm():
374374
# is to check if pydicom is installed:
375375
# pylint: disable=import-outside-toplevel
376376
# pylint: disable=import-error
377-
from pydicom import dicomio # type:ignore # noqa: F401
377+
from pydicom import dcmread # type:ignore # noqa: F401
378378

379379
logger.setLevel(logging.WARNING)
380380

@@ -383,9 +383,9 @@ def _imread_dcm(filename, **kwargs):
383383
"""Open DICOM image with pydicom and return a NumPy array"""
384384
# pylint: disable=import-outside-toplevel
385385
# pylint: disable=import-error
386-
from pydicom import dicomio # type:ignore
386+
from pydicom import dcmread # type:ignore
387387

388-
dcm = dicomio.read_file(filename, force=True)
388+
dcm = dcmread(filename, force=True)
389389
# **********************************************************************
390390
# The following is necessary until pydicom numpy support is improved:
391391
# (after that, a simple: 'arr = dcm.PixelArray' will work the same)

plotpy/tools/misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ class SnapshotParam(DataSet):
176176
# the extension .dcm is not registered in the io module, so we will not
177177
# get here.
178178
try:
179-
from pydicom import dicomio # pylint: disable=import-outside-toplevel
179+
from pydicom import dcmread # pylint: disable=import-outside-toplevel
180180
except ImportError:
181181
raise ImportError("This should not happen (pydicom is not installed)")
182182

183-
model_dcm = dicomio.read_file(model_fname)
183+
model_dcm = dcmread(model_fname)
184184
try:
185185
ps_attr = "ImagerPixelSpacing"
186186
ps_x, ps_y = getattr(model_dcm, ps_attr)

0 commit comments

Comments
 (0)