Skip to content

Commit

Permalink
DICOM redactor improvement: Preventing distortion when multiple sets …
Browse files Browse the repository at this point in the history
…of pixels are in one instance (#1109)

* Adding in handling for instances with icon image sequence data

* Linting fix

---------

Co-authored-by: Omri Mendels <omri374@users.noreply.github.com>
  • Loading branch information
niwilso and omri374 authored Jul 10, 2023
1 parent d51ff56 commit a1c5c30
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,27 @@ def _set_bbox_color(

return box_color

@staticmethod
def _check_if_has_image_icon_sequence(
instance: pydicom.dataset.FileDataset
) -> bool:
"""Check if there is an image icon sequence tag in the metadata.
This leads to pixel data being present in multiple locations.
:param instance: DICOM instance.
:return: Boolean for whether the instance has an image icon sequence tag.
"""
has_image_icon_sequence = False
try:
_ = instance[0x0088, 0x0200]
has_image_icon_sequence = True
except KeyError:
has_image_icon_sequence = False

return has_image_icon_sequence

@classmethod
def _add_redact_box(
cls,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def mock_engine():
Path(TEST_DICOM_PARENT_DIR),
[
Path(TEST_DICOM_PARENT_DIR, "0_ORIGINAL.dcm"),
Path(TEST_DICOM_PARENT_DIR, "0_ORIGINAL_icon_image_sequence.dcm"),
Path(TEST_DICOM_PARENT_DIR, "0_ORIGINAL_no_pixels.dcm"),
Path(TEST_DICOM_PARENT_DIR, "RGB_ORIGINAL.dcm"),
Path(TEST_DICOM_DIR_2, "1_ORIGINAL.DCM"),
Expand Down Expand Up @@ -538,7 +539,7 @@ def test_add_padding_exceptions(
"src_path, expected_num_of_files",
[
(Path(TEST_DICOM_PARENT_DIR, "0_ORIGINAL.dcm"), 1),
(Path(TEST_DICOM_PARENT_DIR), 16),
(Path(TEST_DICOM_PARENT_DIR), 17),
(Path(TEST_DICOM_DIR_1), 3),
(Path(TEST_DICOM_DIR_2), 2),
(Path(TEST_DICOM_DIR_3), 1),
Expand Down Expand Up @@ -909,6 +910,42 @@ def test_set_bbox_color_exceptions(
assert expected_error_type == exc_info.typename


# ------------------------------------------------------
# DicomImageRedactorEngine._check_if_has_image_icon_sequence()
# ------------------------------------------------------
@pytest.mark.parametrize(
"dcm_path, has_sequence",
[
(
Path(TEST_DICOM_PARENT_DIR, "0_ORIGINAL.dcm"),
False
),
(
Path(TEST_DICOM_PARENT_DIR, "0_ORIGINAL_icon_image_sequence.dcm"),
True
),
],
)
def test_check_if_has_image_icon_sequence_happy_path(
mock_engine: DicomImageRedactorEngine,
dcm_path: Path,
has_sequence: bool,
):
"""Test happy path for DicomImageRedactorEngine._check_if_has_image_icon_sequence
Args:
mock_engine (DicomImageRedactorEngine): DicomImageRedactorEngine object.
dcm_path (pathlib.Path): Path to DICOM file.
has_sequence (bool): If additional pixel data is available in the instance.
"""
# Arrange
test_instance = pydicom.dcmread(dcm_path)

# Act
test_has_sequence = mock_engine._check_if_has_image_icon_sequence(test_instance)

# Assert
assert test_has_sequence == has_sequence

# ------------------------------------------------------
# DicomImageRedactorEngine._add_redact_box()
# ------------------------------------------------------
Expand Down

0 comments on commit a1c5c30

Please sign in to comment.