Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸 Handle Multidimensional Features in WSIReader #742

Merged
merged 60 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
8bd861d
image with more than three channels
behnazelhaminia Nov 22, 2023
767b640
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 22, 2023
750c256
Support for multichannel
behnazelhaminia Nov 23, 2023
c9548fa
Support for multichannel
behnazelhaminia Nov 23, 2023
574560d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 23, 2023
c150968
Support for multichannel
behnazelhaminia Nov 23, 2023
ae2ad11
:bug: Fix ruff errors.
shaneahmed Nov 23, 2023
30f4f5f
:bug: Fix errors with 2-dimensional images.
shaneahmed Nov 23, 2023
2f0dd1a
:bug: Fix errors with 2-dimensional images.
shaneahmed Nov 23, 2023
1bc132c
:bug: Use nearest neighbour interpolation for boolean image.
shaneahmed Nov 23, 2023
75b2902
Test support for multichannel
behnazelhaminia Nov 24, 2023
5419d7c
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Nov 24, 2023
0575309
Delete the test file
behnazelhaminia Nov 24, 2023
112e4e1
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Nov 24, 2023
112cf1b
:bug: Use nearest neighbour interpolation for boolean image.
shaneahmed Nov 24, 2023
15043ea
:bug: Fix default behaviour for interpolation.
shaneahmed Nov 24, 2023
c962fef
[skip ci] :rewind: Revert changes to the Patch Prediction notebook.
shaneahmed Nov 24, 2023
ebf18cf
:bug: Fix SIM114 unnecessary if statement.
shaneahmed Nov 24, 2023
749be60
:white_check_mark: Add test_read_multi_channel
behnazelhaminia Nov 29, 2023
04cfee7
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Nov 29, 2023
531ee98
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 29, 2023
1e1fbb5
:white_check_mark: Add value check and interpolation for test_read_mu…
behnazelhaminia Dec 1, 2023
a922ccb
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Dec 1, 2023
da968ee
:white_check_mark: Add value check and interpolation for test_read_mu…
behnazelhaminia Dec 1, 2023
cec02a2
:white_check_mark: Add value check and interpolation for test_read_mu…
behnazelhaminia Dec 1, 2023
28cbb3e
:white_check_mark: Added logging, value check and interpolation for t…
behnazelhaminia Jan 18, 2024
5c8a7ea
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
1a350c8
Merge branch 'develop' into more-than-three-channels
shaneahmed Jan 19, 2024
63c4655
:white_check_mark: Added logging, value check and interpolation for t…
behnazelhaminia Jan 25, 2024
025c852
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Jan 25, 2024
9d36e83
:white_check_mark: Added logging, value check and interpolation for t…
behnazelhaminia Jan 25, 2024
41bf21f
Update tiatoolbox/wsicore/wsireader.py
behnazelhaminia Jan 25, 2024
43975a8
Removed a mistake line
behnazelhaminia Jan 25, 2024
2df748d
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Jan 25, 2024
7730642
Removed a mistake line
behnazelhaminia Jan 25, 2024
63251a3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 25, 2024
08d7137
Apply suggestions from code review
behnazelhaminia Jan 25, 2024
9b94024
:bug: Fixed syntax error
behnazelhaminia Jan 26, 2024
643118d
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Jan 26, 2024
167f23f
:bug: Fixed syntax error
behnazelhaminia Jan 26, 2024
2309f19
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 26, 2024
2a6b04f
:bug: Fixed Line too long error
behnazelhaminia Jan 26, 2024
effb434
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Jan 26, 2024
96018a6
:bug: Fixed Line too long error
behnazelhaminia Jan 26, 2024
f422fcb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 26, 2024
875fce5
Add assert for test_read_multi_channel
behnazelhaminia Jan 26, 2024
3b0c6e8
Add assert for test_read_multi_channel
behnazelhaminia Jan 26, 2024
ca38fa5
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Jan 26, 2024
94112fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 26, 2024
7ef908b
Add assert for test_read_multi_channel
behnazelhaminia Jan 26, 2024
ad3a498
Add assert for test_read_multi_channel
behnazelhaminia Jan 26, 2024
b737f0b
Add assert for test_read_multi_channel
behnazelhaminia Jan 26, 2024
5dc5fa1
:white_check_mark: Assert shape and interpolation
behnazelhaminia Jan 26, 2024
d13dc3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 26, 2024
418c3ed
:white_check_mark: Assert shape and interpolation
behnazelhaminia Jan 26, 2024
e697b1d
Merge remote-tracking branch 'origin/more-than-three-channels' into m…
behnazelhaminia Jan 26, 2024
670ce45
Merge branch 'develop' into more-than-three-channels
shaneahmed Feb 2, 2024
e2758a3
Merge branch 'develop' into more-than-three-channels
shaneahmed Feb 16, 2024
1e63e3f
Merge branch 'develop' into more-than-three-channels
shaneahmed Feb 23, 2024
0c78b40
:white_check_mark: Fix interpolation test.
shaneahmed Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,336 changes: 668 additions & 668 deletions examples/04-patch-extraction.ipynb

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Import modules required to run the Jupyter notebook."""
shaneahmed marked this conversation as resolved.
Show resolved Hide resolved
# Clear logger to use tiatoolbox.logger
import logging

if logging.getLogger().hasHandlers():
logging.getLogger().handlers.clear()

import numpy as np

from tiatoolbox.tools import patchextraction

input_img = np.zeros((1000, 1000, 6))

patch_extractor = patchextraction.get_patch_extractor(
input_img=input_img, # input image path, numpy array, or WSI object
# path to list of points (csv, json), numpy list, panda DF
method_name="slidingwindow", # also supports "slidingwindow"
patch_size=(
32,
32,
), # size of the patch to extract around the centroids from centroids_list
resolution=0,
units="level",
)

i = 1
# show only first 16 patches
num_patches_to_show = 16

for patch in patch_extractor:
print(i)
i += 1
31 changes: 26 additions & 5 deletions tiatoolbox/wsicore/wsireader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2781,8 +2781,14 @@ class VirtualWSIReader(WSIReader):
:func:`~tiatoolbox.utils.image.sub_pixel_read`.

Attributes:
img (:class:`numpy.ndarray`)
mode (str)
img (:class:`numpy.ndarray`):
Input image as :class:`numpy.ndarray`.
mode (str):
Mode of the input image. Default is 'rgb'. Allowed values
are: rgb, bool, feature. "rgb" mode supports bright-field color images.
"bool" mode supports binary masks,
interpolation in this case will be "nearest" instead of "bicubic".
"feature" mode allows multichannel features.

Args:
input_img (str, :obj:`Path`, :class:`numpy.ndarray`):
Expand All @@ -2791,7 +2797,10 @@ class VirtualWSIReader(WSIReader):
Metadata for the virtual wsi.
mode (str):
Mode of the input image. Default is 'rgb'. Allowed values
are: rgb, bool.
are: rgb, bool, feature. "rgb" mode supports bright-field color images.
"bool" mode supports binary masks,
interpolation in this case will be "nearest" instead of "bicubic".
"feature" mode allows multichannel features.

"""

Expand All @@ -2809,15 +2818,24 @@ def __init__(
mpp=mpp,
power=power,
)
if mode.lower() not in ["rgb", "bool"]:
if mode.lower() not in ["rgb", "bool", "feature"]:
msg = "Invalid mode."
raise ValueError(msg)
self.mode = mode.lower()

if isinstance(input_img, np.ndarray):
self.img = input_img
else:
self.img = utils.imread(self.input_path)

if mode != "bool":
if self.img.ndim == 2: # noqa: PLR2004, SIM114
mode = "feature"

elif self.img.shape[2] not in [3, 4]:
mode = "feature"

self.mode = mode.lower()

if info is not None:
self._m_info = info

Expand Down Expand Up @@ -3264,6 +3282,9 @@ class docstrings for more information.
)
bounds_at_read = utils.transforms.locsize2bounds(location_at_read, size_at_read)

if self.mode == "bool":
interpolation = "nearest"

if interpolation in [None, "none"]:
interpolation = None

Expand Down
Loading