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

Issue in patch extraction from images with more than 3 channels #610

Closed
Arwa-AlRubaian opened this issue May 19, 2023 · 3 comments · Fixed by #742
Closed

Issue in patch extraction from images with more than 3 channels #610

Arwa-AlRubaian opened this issue May 19, 2023 · 3 comments · Fixed by #742
Assignees
Labels
enhancement New feature or request

Comments

@Arwa-AlRubaian
Copy link

  • TIA Toolbox version:1.3.3
  • Python version: 3.10
  • Operating System: Ubuntu

Description

I was using (patchextractor=patchextraction.SlidingWindowPatchExtractor) to extract patches on images with 6 channels. Then when iterating over the patches using :
for patch in patchextractor:
#(some code ...)

the following erroroccur:
Traceback (most recent call last):
for patch in patchextractor:
File "//site-packages/tiatoolbox/tools/patchextraction.py", line 167, in next
return self[n]
File "/
/site-packages/tiatoolbox/tools/patchextraction.py", line 179, in getitem
return self.wsi.read_rect(
File "//site-packages/tiatoolbox/wsicore/wsireader.py", line 2846, in read_rect
return self._read_rect_at_resolution(
File "/
/site-packages/tiatoolbox/wsicore/wsireader.py", line 970, in _read_rect_at_resolution
return self.read_bounds(
File "///site-packages/tiatoolbox/wsicore/wsireader.py", line 3057, in read_bounds
return utils.transforms.background_composite(image=im_region)
File "/
//site-packages/tiatoolbox/utils/transforms.py", line 41, in background_composite
image = Image.fromarray(image)
File "/****/site-packages/PIL/Image.py", line 3083, in fromarray
raise TypeError(msg) from e
TypeError: Cannot handle this data type: (1, 1, 6), |u1

@John-P
Copy link
Contributor

John-P commented May 26, 2023

We do not currently have support in place for multi-channel images as we have been focused on RGB bright-field imaging. However, we would love to add support for this and getting patch extraction working for multi-channel images would be a good start. I think the trickiest part would be to define how patches get written out to disk. Do you have a preferred format for this? Would a multi-channel TIFF or npy file be suitable for your needs?

@rogertrullo
Copy link
Contributor

Maybe this should be left up to the user? as long as the patch_extractor returns a np array e.g. H,W,num_chans it should be good?

@shaneahmed shaneahmed self-assigned this Jun 2, 2023
@shaneahmed shaneahmed added this to the Release v1.5.0 milestone Jun 2, 2023
@shaneahmed shaneahmed added the enhancement New feature or request label Jun 2, 2023
@shaneahmed
Copy link
Member

  • Allow the user to select the background colour for background_colour = [1 1 1].
  • Instead of mode, alpha_channel = None if not background composite required, otherwise alpha_channel = -1 by default.
  • background_composite is defined here
    def background_composite(

@shaneahmed shaneahmed linked a pull request Nov 24, 2023 that will close this issue
shaneahmed added a commit that referenced this issue Feb 29, 2024
- Adds support for multichannel inputs e.g., image masks, feature maps etc. Fixes #609 and #610 

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants