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

extraction error #422

Open
CaiYitao opened this issue Jul 10, 2022 Discussed in #420 · 9 comments
Open

extraction error #422

CaiYitao opened this issue Jul 10, 2022 Discussed in #420 · 9 comments
Assignees

Comments

@CaiYitao
Copy link

Discussed in #420

Originally posted by CaiYitao July 6, 2022
Just tried out to extract GridTiler, but get the following error:

Traceback (most recent call last):
  File ~/miniconda3/envs/ml/lib/python3.9/site-packages/PIL/Image.py", line 669, in _repr_png_
    id(self),
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/PIL/Image.py", line 2307, in save
    :returns: A tuple containing bands.
KeyError: 'PNG'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/IPython/core/formatters.py", line 222, in catch_format_error
    r = method(self, *args, **kwargs)
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/IPython/core/formatters.py", line 343, in __call__
    return method()
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/PIL/Image.py", line 671, in _repr_png_
ValueError: Could not save to PNG for display

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 1993, in showtraceback
    stb = self.InteractiveTB.structured_traceback(
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/IPython/core/ultratb.py", line 1118, in structured_traceback
    return FormattedTB.structured_traceback(
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/IPython/core/ultratb.py", line 1012, in structured_traceback
    return VerboseTB.structured_traceback(
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/IPython/core/ultratb.py", line 865, in structured_traceback
    formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/IPython/core/ultratb.py", line 818, in format_exception_as_a_whole
    frames.append(self.format_record(r))
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/IPython/core/ultratb.py", line 736, in format_record
    result += ''.join(_format_traceback_lines(frame_info.lines, Colors, self.has_colors, lvals))
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/stack_data/core.py", line 698, in lines
    pieces = self.included_pieces
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/stack_data/core.py", line 649, in included_pieces
    pos = scope_pieces.index(self.executing_piece)
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/stack_data/utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/stack_data/core.py", line 628, in executing_piece
    return only(
  File "~/miniconda3/envs/ml/lib/python3.9/site-packages/executing/executing.py", line 164, in only
    raise NotOneValueFound('Expected one value, found 0')
executing.executing.NotOneValueFound: Expected one value, found 0

Is it because my PIL library is not compatible with histolab?

my slide is in ".mrxs" format, I also tried to set suffix to .jpg but got same error

grid_tiles_extractor = GridTiler(
   tile_size=(512, 512),
   level=0,
   check_tissue=True, # default
   pixel_overlap=0, # default
   prefix="grid/", # save tiles in the "grid" subdirectory of slide's processed_path
   suffix=".jpg" 
)
```</div>
@CaiYitao
Copy link
Author

Is this normal?
my slide is a ".mrxs" file
image

@ernestoarbitrio
Copy link
Member

Hi @CaiYitao could you provide detailed info about:

  • operating system
  • python version
  • histolab version
  • PIL
  • openslide
    Thanks.

@CaiYitao
Copy link
Author

CaiYitao commented Jul 11, 2022

Rocky Linux 8.6
python 3.9
histolab 0.5.1 (when installing histolab it downgraded the pillow from 9.2 to 8.4)
PIL version 8.4 (also installed libiconv which was accompanied with pillow 9.2 version)
openslide 1.2

Thank you for your prompt reply!

@CaiYitao
Copy link
Author

I also tried with another dataset which is ".svs" format
the timing is great but the grid is not complete
image

@CaiYitao
Copy link
Author

tried to extract with tissue percentage = 1 or 0.95

grid_tiles_extractor = GridTiler(
   tile_size=(224, 224),
   level=0,
   check_tissue=True, # default
   tissue_percent=0.95,
   pixel_overlap=0, # default
   prefix="grid/", # save tiles in the "grid" subdirectory of slide's processed_path
   suffix=".png", # default" 
)

got the following results only the upper one was processed the lower one was not
Is there a way to process all the parts in one slide?
image

and how to speed up .mrxs format processing time? it took a very long time for this format.

@ernestoarbitrio
Copy link
Member

Hi @CaiYitao . We will respond ASAP, probably next week.

@CaiYitao
Copy link
Author

Hi @ernestoarbitrio, Could we extract all the parts in one slide now?

@alessiamarcolini
Copy link
Collaborator

Hi @CaiYitao

Could we extract all the parts in one slide now?

The result you're showing is compatible with the default tiling behavior, i.e., extracting tiles from the biggest tissue portion in the slide. This behavior is controlled by the parameter extraction_mask in the locate_tiles or extract method of the tiler, which has histolab.masks.BiggestTissueBoxMask() as default value.

Therefore, if you want to extract tiles from all the tissue found in the slide you need to instantiate the histolab.masks.TissueMask extraction mask and pass it to extraction_mask.

from histolab.masks import TissueMask

# your code here

grid_tiles_extractor.locate_tiles(
        slide=slide,
        extraction_mask=TissueMask(),
        # your params
    )

@CaiYitao
Copy link
Author

CaiYitao commented Jul 26, 2022

Hi @alessiamarcolini,
Thank you very much for your prompt reply!
and this works!!!

Did we find out why it took a very long time to process the .mrxs file?
The following processing time is just for one .mrxs file.
image

extract the following tiles.image
image

BTW, can we write the tiles as jpg? when I set the suffix= ".jpg" and extract the tiles.
It gave an error like this:

--> 632     raise OSError(f"cannot write mode {im.mode} as JPEG") from e
    634 info = im.encoderinfo
    636 dpi = [round(x) for x in info.get("dpi", (0, 0))]

OSError: cannot write mode RGBA as JPEG

Thank you!

@ernestoarbitrio ernestoarbitrio self-assigned this Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants