tiatoolbox icon indicating copy to clipboard operation
tiatoolbox copied to clipboard

Get ValueError: Unsupported axes `YX` when using OME-TIFF for nuclear segmentation

Open Calebium opened this issue 3 years ago • 4 comments

  • TIA Toolbox version: 1.3.0
  • Python version: 3.7
  • Operating System: Cent OS

Description

When I try to perform nuclear segmentation using an OME-TIFF file, I get the following error:

ValueError: Unsupported axes YX.

What I Did

wsi_output = objInstSegmentor.predict(
    ['TestSet_ROI_6291.ome.tiff'], 
    ioconfig=objIOConfig, 
    masks=None, 
    save_dir=f'WSITest/', 
    mode="wsi", 
    on_gpu=ON_GPU, 
    crash_on_exception=True, 
)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/local/55164614/ipykernel_10371/3581917802.py in <module>
     54     mode="wsi",
     55     on_gpu=ON_GPU,
---> 56     crash_on_exception=True,
     57 )

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/models/engine/semantic_segmentor.py in predict(self, imgs, masks, mode, on_gpu, ioconfig, patch_input_shape, patch_output_shape, stride_shape, resolution, units, save_dir, crash_on_exception)
   1326         for wsi_idx, img_path in enumerate(imgs):
   1327             self._predict_wsi_handle_exception(
-> 1328                 imgs, wsi_idx, img_path, mode, ioconfig, save_dir, crash_on_exception
   1329             )
   1330 

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/models/engine/semantic_segmentor.py in _predict_wsi_handle_exception(self, imgs, wsi_idx, img_path, mode, ioconfig, save_dir, crash_on_exception)
   1177             wsi_save_path = save_dir.joinpath(f"{wsi_idx}")
   1178             if crash_on_exception:
-> 1179                 raise err
   1180             logging.error("Crashed on %s", wsi_save_path)
   1181 

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/models/engine/semantic_segmentor.py in _predict_wsi_handle_exception(self, imgs, wsi_idx, img_path, mode, ioconfig, save_dir, crash_on_exception)
   1153         try:
   1154             wsi_save_path = save_dir.joinpath(f"{wsi_idx}")
-> 1155             self._predict_one_wsi(wsi_idx, ioconfig, str(wsi_save_path), mode)
   1156 
   1157             # Do not use dict with file name as key, because it can be

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/models/engine/nucleus_instance_segmentor.py in _predict_one_wsi(self, wsi_idx, ioconfig, save_path, mode)
    632         mask_path = None if self.masks is None else self.masks[wsi_idx]
    633         wsi_reader, mask_reader = self.get_reader(
--> 634             wsi_path, mask_path, mode, self.auto_generate_mask
    635         )
    636 

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/models/engine/semantic_segmentor.py in get_reader(img_path, mask_path, mode, auto_get_mask)
    670         """Define how to get reader for mask and source image."""
    671         img_path = pathlib.Path(img_path)
--> 672         reader = WSIReader.open(img_path)
    673 
    674         mask_reader = None

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/wsicore/wsireader.py in open(input_img, mpp, power)
    226 
    227         if suffixes[-2:] in ([".ome", ".tiff"],):
--> 228             return TIFFWSIReader(input_path, mpp=mpp, power=power)
    229 
    230         if last_suffix in (".tif", ".tiff") and is_tiled_tiff(input_path):

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/wsicore/wsireader.py in __init__(self, input_img, mpp, power, series, cache_size)
   3055                 return np.prod(self._canonical_shape(page.shape)[:2])
   3056 
-> 3057             series_areas = [page_area(s.pages[0]) for s in all_series]  # skipcq
   3058             self.series_n = np.argmax(series_areas)
   3059         self._tiff_series = self.tiff.series[self.series_n]

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/wsicore/wsireader.py in <listcomp>(.0)
   3055                 return np.prod(self._canonical_shape(page.shape)[:2])
   3056 
-> 3057             series_areas = [page_area(s.pages[0]) for s in all_series]  # skipcq
   3058             self.series_n = np.argmax(series_areas)
   3059         self._tiff_series = self.tiff.series[self.series_n]

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/wsicore/wsireader.py in page_area(page)
   3053             def page_area(page: tifffile.TiffPage) -> float:
   3054                 """Calculate the area of a page."""
-> 3055                 return np.prod(self._canonical_shape(page.shape)[:2])
   3056 
   3057             series_areas = [page_area(s.pages[0]) for s in all_series]  # skipcq

~/.conda/envs/single_cell/lib/python3.7/site-packages/tiatoolbox/wsicore/wsireader.py in _canonical_shape(self, shape)
   3088         if self._axes == "SYX":
   3089             return np.roll(shape, -1)
-> 3090         raise ValueError(f"Unsupported axes `{self._axes}`.")
   3091 
   3092     def _parse_svs_metadata(self) -> dict:

ValueError: Unsupported axes `YX`.

Calebium avatar Nov 05 '22 00:11 Calebium

Hi there, I just wanted to clarify what is happening here. Axes of YX indicates that this is a grayscale image. I am wondering whether this is the case or if it is a planar TIFF being interpreted incorrectly. Are you able to share a sample file?

John-P avatar Nov 11 '22 12:11 John-P

Hi, I think I can send over a sample file. But I cannot attach it to github, what is the best way to do this?

Thanks,

Caleb

Calebium avatar Nov 24 '22 09:11 Calebium

@John-P just chiming in here, I have seen several ome.tiff files where the tiff tag is YX, and they can be either rgb or even multichannel. For example if we use bioformats tools to convert svs files to ome.tiff bioformats2raw followed by raw2ometif this is the case.

rogertrullo avatar Feb 14 '23 19:02 rogertrullo

Partially fixed in #777 and #825

shaneahmed avatar Jun 28 '24 11:06 shaneahmed