Skip to content

Commit

Permalink
Merged in bugfix/RAM-3795_xim_32bit (pull request #422)
Browse files Browse the repository at this point in the history
RAM-3795 Add support for uint32 XIM images

Approved-by: Randy Taylor
Approved-by: Hasan Ammar
  • Loading branch information
jrkerns committed Jul 24, 2024
2 parents 2091df1 + 2e2c0a5 commit eecbc79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Metrics
Core
^^^^

* :bdg-warning:`Fixed` XIM images with uint32 datatypes were not being parsed correctly, leading to a
datatype overflow. `Issue #501 <https://github.com/jrkerns/pylinac/issues/501>`__.
* :bdg-success:`Feature` Most modules have a new documentation section "Analysis Parameters". This section is meant
to guide RadMachine users through the parameters available to them. Sometimes the names are slightly
different and some parameters are not available to the user in RadMachine. Select the tab
Expand Down
13 changes: 12 additions & 1 deletion pylinac/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,18 @@ def _parse_compressed_bytes(
"""
img_height = self.img_height_px
img_width = self.img_width_px
dtype = np.int8 if self.bytes_per_pixel == 1 else np.int16
if self.bytes_per_pixel == 1:
dtype = np.uint8
elif self.bytes_per_pixel == 2:
dtype = np.uint16
elif self.bytes_per_pixel == 4:
dtype = np.uint32
elif self.bytes_per_pixel == 8:
dtype = np.uint64
else:
raise ValueError(
"The XIM image has an unsupported bytes per pixel value. Raise a ticket on the pylinac Github with this file."
)
compressed_array = a = np.zeros((img_height * img_width), dtype=dtype)
# first row and 1st element, 2nd row is uncompressed
# this SHOULD work by reading the # of bytes specified in the header but AFAICT this is just a standard int (4 bytes)
Expand Down
6 changes: 6 additions & 0 deletions tests_basic/core/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,12 @@ def test_overflow(self):
# reset to old settings
np.seterr(**old_settings)

def test_32bit_image(self):
xim_path = get_file_from_cloud_test_repo(["xim_uint32.xim"])
xim = XIM(xim_path)
self.assertEqual(xim.array.dtype, np.uint32)
self.assertEqual(xim.array.max(), 38822)


class TestLinacDicomImage(TestCase):
def test_normal_image(self):
Expand Down

0 comments on commit eecbc79

Please sign in to comment.