Skip to content

Commit aafa4e9

Browse files
committed
fix post_proc behaviour in AnnotationStoreReader
1 parent 7f84729 commit aafa4e9

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

tests/test_wsireader.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,11 +2977,10 @@ def test_post_proc_logic_across_readers(wsi: WSIReader) -> None:
29772977
called: dict[str, bool] = {"flag": False}
29782978
mock_post_proc = _make_mock_post_proc(called)
29792979

2980-
skip_check = isinstance(wsi, AnnotationStoreReader) # and wsi.base_wsi is None
2980+
skip_check = isinstance(wsi, AnnotationStoreReader)
29812981

2982-
if skip_check is False:
2983-
# Recursively inject post_proc into the actual reader
2984-
_inject_post_proc_recursive(wsi, mock_post_proc)
2982+
# Recursively inject post_proc into the actual reader
2983+
_inject_post_proc_recursive(wsi, mock_post_proc)
29852984

29862985
patch_utils = _should_patch_background_composite(wsi)
29872986

@@ -2999,7 +2998,7 @@ def test_post_proc_logic_across_readers(wsi: WSIReader) -> None:
29992998
if skip_check:
30002999
assert isinstance(rect, np.ndarray)
30013000
assert isinstance(region, np.ndarray)
3002-
assert not called["flag"]
3001+
assert called["flag"]
30033002
return
30043003

30053004
if isinstance(wsi, NGFFWSIReader):
@@ -3107,6 +3106,10 @@ def test_explicit_none_postproc(sample_svs: Path) -> None:
31073106
assert isinstance(region, np.ndarray)
31083107
assert region.shape == (50, 50, 3)
31093108

3109+
region = reader.read_rect((0, 0), (50, 50), coord_space="resolution")
3110+
assert isinstance(region, np.ndarray)
3111+
assert region.shape == (50, 50, 3)
3112+
31103113

31113114
def test_fsspec_json_wsi_reader_instantiation() -> None:
31123115
"""Test if FsspecJsonWSIReader is instantiated.

tiatoolbox/wsicore/wsireader.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6486,8 +6486,6 @@ def read_rect(
64866486
coord_space=coord_space,
64876487
**kwargs,
64886488
)
6489-
if self.post_proc is not None:
6490-
base_region = self.post_proc(base_region)
64916489
base_region = Image.fromarray(
64926490
utils.transforms.background_composite(base_region, alpha=True),
64936491
)
@@ -6498,7 +6496,12 @@ def read_rect(
64986496
)
64996497
base_region = Image.alpha_composite(base_region, im_region)
65006498
base_region = base_region.convert("RGB")
6501-
return np.array(base_region)
6499+
base_region = np.array(base_region)
6500+
if self.post_proc is not None:
6501+
base_region = self.post_proc(base_region)
6502+
return base_region
6503+
if self.post_proc is not None:
6504+
im_region = self.post_proc(im_region)
65026505
return utils.transforms.background_composite(im_region, alpha=False)
65036506

65046507
def read_bounds(
@@ -6681,8 +6684,6 @@ class docstrings for more information.
66816684
coord_space=coord_space,
66826685
**kwargs,
66836686
)
6684-
if self.post_proc is not None:
6685-
base_region = self.post_proc(base_region)
66866687
base_region = Image.fromarray(
66876688
utils.transforms.background_composite(base_region, alpha=True),
66886689
)
@@ -6693,7 +6694,12 @@ class docstrings for more information.
66936694
)
66946695
base_region = Image.alpha_composite(base_region, im_region)
66956696
base_region = base_region.convert("RGB")
6696-
return np.array(base_region)
6697+
base_region = np.array(base_region)
6698+
if self.post_proc is not None:
6699+
base_region = self.post_proc(base_region)
6700+
return base_region
6701+
if self.post_proc is not None:
6702+
im_region = self.post_proc(im_region)
66976703
return utils.transforms.background_composite(im_region, alpha=False)
66986704

66996705

0 commit comments

Comments
 (0)