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

[BUG] Compression scheme 33003 tile decoding is not implemented. #17

Closed
OlivierDehaene opened this issue Apr 21, 2021 · 4 comments · Fixed by #19
Closed

[BUG] Compression scheme 33003 tile decoding is not implemented. #17

OlivierDehaene opened this issue Apr 21, 2021 · 4 comments · Fixed by #19
Labels
bug Something isn't working

Comments

@OlivierDehaene
Copy link

OlivierDehaene commented Apr 21, 2021

Describe the bug

For Aperio svs files, I run into a cryptic error:

/slide.svs: Compression scheme 33003 tile decoding is not implemented.

However, cuCMI still loads a tile and doesn't raise but the color are wrong or it is entirely black. See the following grid of tiles:

image

Are all OpenSlide vendors supported? Is there a list of all supported vendors somewhere? I could not find it.

Steps/Code to reproduce bug

# Download the TCGA-F4-6459-01Z-00-DX1 slide from https://portal.gdc.cancer.gov/cases/9fd08502-355b-4f5a-a25c-73ec7184f6d3?bioId=57f4136d-d6aa-4537-ba73-f21fe0374005 

import numpy as np

from PIL import Image
from cucmi import CuImage

slide = CuImage("TCGA-F4-6459-01Z-00-DX1")

tile = slide.read_region((0, 0), (224, 224), 0)

Image.fromarray(np.asarray(tile))
@OlivierDehaene OlivierDehaene added the bug Something isn't working label Apr 21, 2021
@gigony
Copy link
Contributor

gigony commented Apr 22, 2021

Hello @OlivierDehaene !
Thank you for your interest in cuCIM!

Compression scheme 33003 is actually JPEG2000 which is used in Aperio SVS format.

cuCIM currently supports tiled RGB TIFF image(Generic TIFF or Philips TIFF) with JPEG or Deflate compressed and doesn't support SVS format yet.
However, we have a plan to support it in the near future.

The tentative plan is specified in the following link (I would move the content to Github wiki page later):
https://github.com/rapidsai/cucim/blob/branch-0.20/python/cucim/docs/roadmap/index.md#facalendar-alttext-info-mr-1-v020

If cuCIM encounters TIFF (SVS is a variant of TIFF format) file that is not JPEG/Deflate compressed RGB format, it just delegates its process to libtiff's TIFFRGBAImageGet() method and it seems that warning/error are not properly handled.

Let me fix the issue by raising an error until cuCIM supports SVS format properly.
(I am currently working on providing a cache mechanism to cuCIM so that the performance could be greatly improved)

Thank you for the report! We are also eager to support various image formats so stay tuned!

gigony added a commit to gigony/cucim that referenced this issue Apr 22, 2021
gigony added a commit to gigony/cucim that referenced this issue Apr 22, 2021
SVS format is not supported for now but we loosen the restriction by
delegating its process to libtiff's TIFFRGBAImageGet() method.
cuCIM assumes that only one image with Subfile Type(=0) is available in
the image file but apparently, some SVS files have also only one Subfile
Type with zero so bypassing the check.

This patch explicitly checks SVS format and compression methods and
raises an exception if the given file doesn't match the criteria.
Once SVS format is supported, those changes need to be updated to not
raise exceptions for SVS files.
@OlivierDehaene
Copy link
Author

Thank you for your answer @gigony!

However, we have a plan to support it in the near future.

Amazing! I have been looking for a better alternative to OpenSlide for a while now and if cuCIM starts to support Aperio that would be great :)

I am currently working on providing a cache mechanism to cuCIM so that the performance could be greatly improved

Will we be able to disable the cache when doing random tile reads? We generally disable the OpenSlide one when training.

@gigony
Copy link
Contributor

gigony commented Apr 23, 2021

@OlivierDehaene

Will we be able to disable the cache when doing random tile reads? We generally disable the OpenSlide one when training.

I thought cuCIM can allocate some memory for cache by default and the user can increase the cache size programmatically. I assumed it wouldn't be a problem if we use a cache memory per 'parent process' and cache memory is shared among subprocesses (whereas OpenSlide seems to allocate cache memory per file).

However, you're right. It is better to have an option to disable cache at all as cache wouldn't much help when reading random partial images from a huge image pool during training.

Now I am thinking of allocating cache memory only when requested :)

Thank you so much for your valuable feedback!

@rapids-bot rapids-bot bot closed this as completed in #19 May 5, 2021
rapids-bot bot pushed a commit that referenced this issue May 5, 2021
SVS format is not supported for now but we loosen the restriction by
delegating its process to libtiff's TIFFRGBAImageGet() method.
cuCIM assumes that only one image with Subfile Type(=0) is available in
the image file but apparently, some SVS files have also only one Subfile
Type with zero so bypassing the check.

This patch explicitly checks SVS format and compression methods and
raises an exception if the given file doesn't match the criteria.
Once SVS format is supported, those changes need to be updated to not
raise exceptions for SVS files.

Resolves: #17

Authors:
  - Gigon Bae (https://github.com/gigony)

Approvers:
  - Benjamin Zaitlen (https://github.com/quasiben)
  - https://github.com/jakirkham

URL: #19
@jakirkham
Copy link
Member

Some packages should be pushed to rapidsai-nightly soon with Gigon's fix. Also this should show up in the next release. Please let us know if you run into any more issues 🙂

rapids-bot bot pushed a commit that referenced this issue Sep 30, 2021
Due to #17 ([BUG] Compression scheme 33003 tile decoding is not implemented), #19 (Check compression method used in the image) was merged so cuCIM has been handling only particular formats (only jpeg/deflate-compressed image).

If the input TIFF image has no-compressed RAW tile image, cuCIM showed the following error message:

> RuntimeError: This format (compression: 1, sample_per_pixel: 1, planar_config: 1, photometric: 1) is not supported yet!. https://github.com/Project-MONAI/MONAI/pull/2987/checks?check_run_id=3667530814#step:7:15641

This patch is to support raw RGB tiled TIFF with fast-path, re-allowing non-compressed image with slow-path (in case the input is not tiled RGB image).

This supports Project-MONAI/MONAI#2987.

Authors:
  - Gigon Bae (https://github.com/gigony)

Approvers:
  - Gregory R. Lee (https://github.com/grlee77)
  - https://github.com/jakirkham

URL: #108
gigony added a commit to gigony/cucim that referenced this issue Nov 1, 2021
- Update Jpeg decoder to consider colorspace of the JPEG image
  - We need to set a proper color space from TIFF metadata to the decoder
  - Update tjDecompress2() method call with jpeg_decode_buffer() that modified
    tjDecompress2() implementation
  - Add `jpeg_color_space_` to IFD Class.
- Move additional includes to their own cmake files
- Add Jpeg2k decoder with OpenJpeg
  - Added fast color conversion logic with pre-calculated table
- Add LZW decoder with libtiff's implementation
  - Take part of the code to provide only LZW decoder part
- Add `rows_per_strip_` and `predictor_` attributers to IFD class, to support
  LZW
- Refactor TIFF:resolve_vendor_format() to support Aperio SVS metadata
- Support LZW compressed image (with multi strips) for associated image.

Addresses rapidsai#17
gigony added a commit to gigony/cucim that referenced this issue Nov 3, 2021
- Update Jpeg decoder to consider colorspace of the JPEG image
  - We need to set a proper color space from TIFF metadata to the decoder
  - Update tjDecompress2() method call with jpeg_decode_buffer() that modified
    tjDecompress2() implementation
  - Add `jpeg_color_space_` to IFD Class.
- Move additional includes to their own cmake files
- Add Jpeg2k decoder with OpenJpeg
  - Added fast color conversion logic with pre-calculated table
- Add LZW decoder with libtiff's implementation
  - Take part of the code to provide only LZW decoder part
- Add `rows_per_strip_` and `predictor_` attributers to IFD class, to support
  LZW
- Refactor TIFF:resolve_vendor_format() to support Aperio SVS metadata
- Support LZW compressed image (with multi strips) for associated image.

Addresses rapidsai#17
gigony added a commit to gigony/cucim that referenced this issue Nov 3, 2021
- Update Jpeg decoder to consider colorspace of the JPEG image
  - We need to set a proper color space from TIFF metadata to the decoder
  - Update tjDecompress2() method call with jpeg_decode_buffer() that modified
    tjDecompress2() implementation
  - Add `jpeg_color_space_` to IFD Class.
- Move additional includes to their own cmake files
- Add Jpeg2k decoder with OpenJpeg
  - Added fast color conversion logic with pre-calculated table
- Add LZW decoder with libtiff's implementation
  - Take part of the code to provide only LZW decoder part
- Add `rows_per_strip_` and `predictor_` attributers to IFD class, to support
  LZW
- Refactor TIFF:resolve_vendor_format() to support Aperio SVS metadata
- Support LZW compressed image (with multi strips) for associated image.

Addresses rapidsai#17
gigony added a commit to gigony/cucim that referenced this issue Nov 9, 2021
- Update Jpeg decoder to consider colorspace of the JPEG image
  - We need to set a proper color space from TIFF metadata to the decoder
  - Update tjDecompress2() method call with jpeg_decode_buffer() that modified
    tjDecompress2() implementation
  - Add `jpeg_color_space_` to IFD Class.
- Move additional includes to their own cmake files
- Add Jpeg2k decoder with OpenJpeg
  - Added fast color conversion logic with pre-calculated table
- Add LZW decoder with libtiff's implementation
  - Take part of the code to provide only LZW decoder part
- Add `rows_per_strip_` and `predictor_` attributers to IFD class, to support
  LZW
- Refactor TIFF:resolve_vendor_format() to support Aperio SVS metadata
- Support LZW compressed image (with multi strips) for associated image.

Addresses rapidsai#17
gigony added a commit to gigony/cucim that referenced this issue Nov 9, 2021
- Update Jpeg decoder to consider colorspace of the JPEG image
  - We need to set a proper color space from TIFF metadata to the decoder
  - Update tjDecompress2() method call with jpeg_decode_buffer() that modified
    tjDecompress2() implementation
  - Add `jpeg_color_space_` to IFD Class.
- Move additional includes to their own cmake files
- Add Jpeg2k decoder with OpenJpeg
  - Added fast color conversion logic with pre-calculated table
- Add LZW decoder with libtiff's implementation
  - Take part of the code to provide only LZW decoder part
- Add `rows_per_strip_` and `predictor_` attributers to IFD class, to support
  LZW
- Refactor TIFF:resolve_vendor_format() to support Aperio SVS metadata
- Support LZW compressed image (with multi strips) for associated image.

Addresses rapidsai#17
gigony added a commit to gigony/cucim that referenced this issue Nov 20, 2021
- Update Jpeg decoder to consider colorspace of the JPEG image
  - We need to set a proper color space from TIFF metadata to the decoder
  - Update tjDecompress2() method call with jpeg_decode_buffer() that modified
    tjDecompress2() implementation
  - Add `jpeg_color_space_` to IFD Class.
- Move additional includes to their own cmake files
- Add Jpeg2k decoder with OpenJpeg
  - Added fast color conversion logic with pre-calculated table
- Add LZW decoder with libtiff's implementation
  - Take part of the code to provide only LZW decoder part
- Add `rows_per_strip_` and `predictor_` attributers to IFD class, to support
  LZW
- Refactor TIFF:resolve_vendor_format() to support Aperio SVS metadata
- Support LZW compressed image (with multi strips) for associated image.

Addresses rapidsai#17
rapids-bot bot pushed a commit that referenced this issue Nov 20, 2021
**Add tif_lzw.c from libtiff as it is**
Copy tif_lzw.c file from libtiff for porting lzw decoder.
The code is from the following link:
  https://gitlab.com/libtiff/libtiff/-/blob/8546f7ee994eacff0a563918096f16e0a6078fa2/libtiff/tif_lzw.c
, which is after v4.3.0

**Support Aperio SVS with CPU LZW and jpeg2k decoder**
- Update Jpeg decoder to consider colorspace of the JPEG image
  - We need to set a proper color space from TIFF metadata to the decoder
  - Update tjDecompress2() method call with jpeg_decode_buffer() that modified tjDecompress2() implementation
  - Add `jpeg_color_space_` to IFD Class.
- Move additional includes to their own CMake files
- Add Jpeg2k decoder with OpenJpeg
  - Added fast color conversion logic with pre-calculated table
- Add LZW decoder with libtiff's implementation
  - Take part of the code to provide only LZW decoder part
- Add `rows_per_strip_` and `predictor_` attributes to IFD class, to support LZW
- Refactor TIFF:resolve_vendor_format() to support Aperio SVS metadata
- Support LZW compressed image (with multi strips) for the associated image.

Addresses #17

![image](https://user-images.githubusercontent.com/1928522/140428606-cb8fafd0-69aa-4eb5-a5af-9e6da17e0fc9.png)

![image](https://user-images.githubusercontent.com/1928522/140428632-06de39da-8286-48de-9565-a796cd62608b.png)

![image](https://user-images.githubusercontent.com/1928522/140428661-e9ee371d-d685-442c-89ec-468c62b5a5af.png)

Authors:
  - Gigon Bae (https://github.com/gigony)

Approvers:
  - https://github.com/jakirkham

URL: #141
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants