|
28 | 28 |
|
29 | 29 | from tiatoolbox import cli, utils |
30 | 30 | from tiatoolbox.annotation import SQLiteStore |
31 | | -from tiatoolbox.utils import imread, tiff_to_fsspec |
| 31 | +from tiatoolbox.utils import imread, postproc_defs, tiff_to_fsspec |
32 | 32 | from tiatoolbox.utils.exceptions import FileNotSupportedError |
33 | 33 | from tiatoolbox.utils.magic import is_sqlite3 |
34 | 34 | from tiatoolbox.utils.transforms import imresize, locsize2bounds |
@@ -2934,6 +2934,29 @@ def test_visualise_multi_channel(sample_qptiff: Path) -> None: |
2934 | 2934 | # Was 7 channels. Not sure if this is correct. Check this! |
2935 | 2935 |
|
2936 | 2936 |
|
| 2937 | +def test_get_post_proc_variants() -> None: |
| 2938 | + """Test different branches of get_post_proc method.""" |
| 2939 | + reader = wsireader.VirtualWSIReader(np.zeros((10, 10, 3))) |
| 2940 | + |
| 2941 | + assert callable(reader.get_post_proc(lambda x: x)) |
| 2942 | + assert reader.get_post_proc(None) is None |
| 2943 | + assert isinstance(reader.get_post_proc("auto"), postproc_defs.MultichannelToRGB) |
| 2944 | + assert isinstance( |
| 2945 | + reader.get_post_proc("MultichannelToRGB"), postproc_defs.MultichannelToRGB |
| 2946 | + ) |
| 2947 | + |
| 2948 | + with pytest.raises(ValueError, match="Invalid post-processing function"): |
| 2949 | + reader.get_post_proc("invalid_proc") |
| 2950 | + |
| 2951 | + |
| 2952 | +def test_post_proc_applied() -> None: |
| 2953 | + """Test that post_proc is applied to image region.""" |
| 2954 | + reader = wsireader.VirtualWSIReader(np.ones((100, 100, 3), dtype=np.uint8)) |
| 2955 | + reader.post_proc = lambda x: x * 0 |
| 2956 | + region = reader.read_rect((0, 0), (50, 50)) |
| 2957 | + assert np.all(region == 0) |
| 2958 | + |
| 2959 | + |
2937 | 2960 | def test_fsspec_json_wsi_reader_instantiation() -> None: |
2938 | 2961 | """Test if FsspecJsonWSIReader is instantiated. |
2939 | 2962 |
|
|
0 commit comments