Skip to content

Commit

Permalink
Fix pydicom support by replacing dicomio with dcmread for reading DIC…
Browse files Browse the repository at this point in the history
…OM files
  • Loading branch information
PierreRaybaut committed Nov 6, 2024
1 parent 99b98ab commit d3c47d9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Supported versions of Python have been updated (drop support for Python 3.8, add
* The `info_callback` is a function that takes the annotation object and returns a string with the information to display
* Default `info_callback` is redirected to the `get_infos` method of the annotation object (this makes the feature backward compatible)

🛠️ Bug fixes:

* Fixed `pydicom` support: use `dcmread` instead of `read_file` to read DICOM files

## Version 2.6.3 ##

🧯 In this release, test coverage is 79%.
Expand Down
4 changes: 2 additions & 2 deletions plotpy/builder/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ def image(
if isinstance(filename, str) and filename.lower().endswith(".dcm"):
# pylint: disable=import-outside-toplevel
# pylint: disable=import-error
from pydicom import dicomio # type:ignore
from pydicom import dcmread # type:ignore

template = dicomio.read_file(filename, stop_before_pixels=True, force=True)
template = dcmread(filename, stop_before_pixels=True, force=True)
ipp = getattr(template, "ImagePositionPatient", ["0", "0", "0"])
pxs = getattr(template, "PixelSpacing", ["1", "1"])
ipx, ipy = float(ipp[0]), float(ipp[1])
Expand Down
6 changes: 3 additions & 3 deletions plotpy/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def _import_dcm():
# is to check if pydicom is installed:
# pylint: disable=import-outside-toplevel
# pylint: disable=import-error
from pydicom import dicomio # type:ignore # noqa: F401
from pydicom import dcmread # type:ignore # noqa: F401

logger.setLevel(logging.WARNING)

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

dcm = dicomio.read_file(filename, force=True)
dcm = dcmread(filename, force=True)
# **********************************************************************
# The following is necessary until pydicom numpy support is improved:
# (after that, a simple: 'arr = dcm.PixelArray' will work the same)
Expand Down
4 changes: 2 additions & 2 deletions plotpy/tools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ class SnapshotParam(DataSet):
# the extension .dcm is not registered in the io module, so we will not
# get here.
try:
from pydicom import dicomio # pylint: disable=import-outside-toplevel
from pydicom import dcmread # pylint: disable=import-outside-toplevel
except ImportError:
raise ImportError("This should not happen (pydicom is not installed)")

model_dcm = dicomio.read_file(model_fname)
model_dcm = dcmread(model_fname)
try:
ps_attr = "ImagerPixelSpacing"
ps_x, ps_y = getattr(model_dcm, ps_attr)
Expand Down

0 comments on commit d3c47d9

Please sign in to comment.