3 Commits
Author SHA1 Message Date
Oleksandr_SaninandSharon Hart 2901c7fcb3 fix(image-redactor): remove double bbox formatting in eval_dicom_instance (#2079)
`verify_dicom_instance` already returns formatted ocr bboxes and
analyzer bboxes (the result of calling `get_bboxes_from_ocr_results`
and `get_bboxes_from_analyzer_results` internally). However,
`eval_dicom_instance` was calling both formatters a second time on those
already-formatted lists, causing a TypeError when list-of-dict results
were indexed with a string key instead of an integer.

Also fix the positional argument mismatch in the `verify_dicom_instance`
call: `use_metadata` was passed as the 4th positional argument but the
4th parameter of `verify_dicom_instance` is `show_text_annotation`.
Changed to a keyword argument to avoid ambiguity.

Closes #1251

Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>
Co-authored-by: Sharon Hart <sharonh.dev@gmail.com>
2026-06-21 13:04:57 +03:00
Oleksandr_SaninandClaude 66318b6042 test(ip-recognizer): add regression tests for IPv6 double-colon bugs (#2062)
Adds two test cases from issue #1476 that were missing from the test
suite, even though the underlying regex bugs have already been fixed:

1. A valid IPv6 address with a single `::` preceded by only one group
   (e.g. `A099::09C0:876A:130B`) must be matched in full rather than
   truncated at the `::`.

2. An invalid IPv6 address containing multiple `::` occurrences
   (e.g. `2001::25de::cade`) must produce no match.

These explicit regression tests guard against future regressions to the
`IpRecognizer` IPv6 pattern.

Closes #1476

Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-06-16 12:30:28 +03:00
Oleksandr_SaninandSharon Hart 83ab7eb856 fix(image-redactor): return rendered image when no text is detected in verify (#2040)
* fix(image-redactor): return rendered image when no text is detected in verify

When `add_custom_bboxes` was called with an empty bboxes list (i.e., no
text detected in the DICOM image), it returned the raw PIL image directly,
bypassing the matplotlib rendering pipeline. This caused two problems:

1. The `use_greyscale_cmap` parameter was ignored, so greyscale DICOM
   images were not rendered with `cmap="gray"`, resulting in a blank or
   colour-mapped image instead of the expected greyscale view.

2. The returned type was an unrendered PIL Image rather than the
   matplotlib-figure-derived PIL Image returned in every other code path,
   leading to inconsistent output and visually empty verification images.

Fix: remove the early-return branch for `len(bboxes) == 0`. The `for`
loop over bboxes is a no-op when the list is empty, so both paths now
share the same matplotlib rendering code. Also add `plt.close(fig)` to
release the figure after rendering to prevent a memory leak.

Add two new parametrised test cases (empty bboxes, greyscale and RGB)
that assert a valid, non-None PIL Image of the correct dimensions is
returned.

Closes #1034

Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>

* fix(image-redactor): render greyscale image via matplotlib when no bboxes found

The previous attempt always routed through matplotlib for empty bboxes,
which broke the integration test
(test_given_image_without_text_and_pii_verify_then_image_does_not_change)
because the RGBA matplotlib output is not pixel-identical to the original
RGB input after resize.

Targeted fix: only bypass the raw-image-return path when
use_greyscale_cmap=True (i.e. greyscale DICOM images).  For those,
ax.imshow must receive cmap="gray" and go through the full matplotlib
rendering pipeline so the image is displayed correctly instead of as a
blank/wrong-colourmap image (the root cause of #1034).  For regular RGB
images with no bboxes the original PIL image is returned directly,
preserving backward compatibility and keeping the integration test green.

Also guard the pixel-colour loop in test_add_custom_bboxes_happy_path so
it only runs when there are bboxes (the loop expects multi-channel pixels
which a mode-L image does not provide).

Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>

---------

Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>
Co-authored-by: Sharon Hart <sharonh.dev@gmail.com>
2026-06-07 12:11:18 +03:00