Skip to content

Commit

Permalink
Fix tests for J2K lossless decoding with MacOS (#2051)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion committed May 7, 2024
1 parent 3118444 commit dfe553f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
jobs:
tests:
strategy:
fail-fast: false
matrix:
# One Python version per OS, one combo does coverage
# PyPy only has one line in pydicom (as of 2003-07) so cover in merge only
Expand All @@ -20,6 +21,10 @@ jobs:
python-version: "3.11"
test-extras: true
upload-coverage: true
- os: macos
python-version: "3.10"
test-extras: true
upload-coverage: false
uses: ./.github/workflows/tests_wf.yml
with:
os: ${{ matrix.os }}
Expand Down
8 changes: 4 additions & 4 deletions tests/pixels/pixels_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ def test(ref, arr, **kwargs):
# J2KI, (8, 8), (1, 480, 640, 3), OB, YBR_ICT, 0
def test(ref, arr, **kwargs):
ref = get_testdata_file("US1_UNCI.dcm", read=True).pixel_array
assert np.array_equal(arr, ref)
assert np.allclose(arr, ref, atol=1)


J2KI_08_08_3_0_1F_YBR_ICT = PixelReference("US1_J2KI.dcm", "u1", test)
Expand All @@ -2061,7 +2061,7 @@ def test(ref, arr, **kwargs):
# J2KI, (16, 10), (1, 1760, 1760, 1), OB, MONOCHROME1, 0
def test(ref, arr, **kwargs):
ref = get_testdata_file("RG3_UNCI.dcm", read=True).pixel_array
assert np.array_equal(arr, ref)
assert np.allclose(arr, ref, atol=1)


J2KI_16_10_1_0_1F_M1 = PixelReference("RG3_J2KI.dcm", "<u2", test)
Expand All @@ -2070,7 +2070,7 @@ def test(ref, arr, **kwargs):
# J2KI, (16, 12), (1, 1024, 1024, 1), OB, MONOCHROME2, 0
def test(ref, arr, **kwargs):
ref = get_testdata_file("MR2_UNCI.dcm", read=True).pixel_array
assert np.array_equal(arr, ref)
assert np.allclose(arr, ref, atol=1)


J2KI_16_12_1_0_1F_M2 = PixelReference("MR2_J2KI.dcm", "<u2", test)
Expand All @@ -2079,7 +2079,7 @@ def test(ref, arr, **kwargs):
# J2KI, (16, 15), (1, 1955, 1841, 1), OB, MONOCHROME1, 0
def test(ref, arr, **kwargs):
ref = get_testdata_file("RG1_UNCI.dcm", read=True).pixel_array
assert np.array_equal(arr, ref)
assert np.allclose(arr, ref, atol=1)


J2KI_16_15_1_0_1F_M1 = PixelReference("RG1_J2KI.dcm", "<u2", test)
Expand Down
23 changes: 20 additions & 3 deletions tests/test_pillow_pixel_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def test_using_pillow_handler_raises(self):
],
),
]
JPEG2K_MATCHING_DATASETS = [
J2KR_MATCHING_DATASETS = [
# (compressed, reference, fixes)
pytest.param(
J2KR_08_08_3_0_1F_YBR_ICT,
Expand Down Expand Up @@ -415,6 +415,9 @@ def test_using_pillow_handler_raises(self):
get_testdata_file("MR_small.dcm"),
{},
),
]
J2KI_MATCHING_DATASETS = [
# (compressed, reference, fixes)
pytest.param(
J2KI_08_08_3_0_1F_RGB,
get_testdata_file("SC_rgb_gdcm2k_uncompressed.dcm"),
Expand Down Expand Up @@ -516,8 +519,8 @@ def test_properties(self, fpath, data):
assert data[5] == arr.shape
assert arr.dtype == data[6]

@pytest.mark.parametrize("fpath, rpath, fixes", JPEG2K_MATCHING_DATASETS)
def test_array(self, fpath, rpath, fixes):
@pytest.mark.parametrize("fpath, rpath, fixes", J2KR_MATCHING_DATASETS)
def test_array_lossless(self, fpath, rpath, fixes):
"""Test pixel_array returns correct values."""
ds = dcmread(fpath)
# May need to correct some element values
Expand All @@ -530,6 +533,20 @@ def test_array(self, fpath, rpath, fixes):
ref = dcmread(rpath).pixel_array
assert np.array_equal(arr, ref)

@pytest.mark.parametrize("fpath, rpath, fixes", J2KI_MATCHING_DATASETS)
def test_array_lossy(self, fpath, rpath, fixes):
"""Test pixel_array returns correct values."""
ds = dcmread(fpath)
# May need to correct some element values
for kw, val in fixes.items():
setattr(ds, kw, val)
arr = ds.pixel_array
if "YBR_FULL" in ds.PhotometricInterpretation:
arr = convert_color_space(arr, ds.PhotometricInterpretation, "RGB")

ref = dcmread(rpath).pixel_array
assert np.allclose(arr, ref, atol=1)

def test_warning(self):
"""Test that the precision warning works OK."""
ds = dcmread(J2KR_16_14_1_1_1F_M2)
Expand Down

0 comments on commit dfe553f

Please sign in to comment.