Visualization problem with TIF in Cytomine

Hello all,

I have just installed Cytomine on a server following the tutorial. Although I am able to upload and browse images from scanner vendors with no problem (I’ve tried MRXS from 3DHistech), I am experiencing visualization issues with custom TIF files.

We are not allowed to use “raw” files from the scanners due to privacy concerns. Therefore, we first convert the slide by reading the entire image on a patch-by-patch basis and writing the tiles to a regular TIF. This way, we convert any image format to an anonymous TIF file.

Although I can browse these TIF files with other tools (e.g. GitHub - computationalpathologygroup/ASAP: Program for the analysis and visualization of whole-slide images in digital pathology), I see image artifacts when they are uploaded to Cytomine. I’ve attached some pictures of these artifacts for two different TIF files.

Do you recognize these artifacts or have any clue what the problem could be? Alternatively, where can I find logs that could help me debug the issue?

Thank you!

Hi,

Thanks for reporting this issue.

Do you know the characteristics of your TIF file: pyramidal TIF or not and the tile size ?
My guess is that Cytomine has some trouble to correctly parse the tile size of your file, because it seems to read part of tiles at wrong offsets.

Cytomine is working well with tiled TIF with tile size = 256. Do you have the possibility to build your TIF with such tile size and retest ?

Best,

Ulysse

Hi Ulysse,

Probably the tilesize is 512, that is the default for our converter. You can find a sample here: https://1drv.ms/u/s!Au5F0tqL0NJPgdpgfx4_WlakHUnJRQ?e=zZRyar

Hello Ulysse,

Thank you for your reply. It is a pyramidal TIF (mimeType: image/pyrtiff according to Cytomine). The image size at the highest magnification is the same in both ASAP and Cytomine.

I just converted an SVS file that works fine using 512 and 256 tile size. Unfortunately, the artifacts persist in these two copies.

Best,
David

Hello,

In order to find out what the problem might be, I decided to convert the images using pyvips and experimented a bit with the parameters of tiffsave (see Image — pyvips 2.1.14 documentation).

First, I tried converting SVS and MRXS valid images with these commands:
vips openslideload “/path/to/file.svs” “/path/to/file.tiff”[tile=true,compression=jpeg,pyramid=true]

I changed these and other command parameters extensively, and I managed to visualize the slides but with a different type of bug (see image below). This time, the image tiles appear separated by some empty space. No success.

However, changing the parameters “depth” or “subifd” triggered an interesting event. Apparently, the resulting images are not compatible with Cytomine right away, and they are automatically converted after upload:

vips openslideload “/path/to/file.svs” “/path/to/file.tiff”[tile=true,compression=jpeg,pyramid=true,depth=one]

Remarkably, these converted images can be visualized in Cytomine with no problem, they look just fine. Unfortunately, this does not solve the entire issue since I do not control this automatic conversion within Cytomine, or its parameters, and it also fails sometimes. Does anyone know how to reproduce this conversion offline or avoid the artifact shown above?

Thank you,
David

Hello Ulysse,

You were right about the patch size. If I convert any of my TIFs using vips with the following command, they look fine in Cytomine:

vips copy “/path/to/my/image.tif” “/path/to/my/image_converted.tif”[pyramid,tile,compression=jpeg,Q=80,tile-width=256,tile-height=256]

However, the resolution is not correctly transferred/set to the output slide. I will investigate what the issue is, and see if I can write the correct tif format without vips.

Best,
David

1 Like

Hi,

Thanks Geert for the image file.

Thanks David for the experiments. Weird results, but interesting :wink:

Geert’s TIF file has:

  1. 1024 tile size for all levels
  2. downsampled pyramid levels until 1 pixel-wide level

Cytomine Community Edition is rather strict on what is accepted as pyramidal tiff:

  1. 256 tile size for all levels
  2. downsampled pyramid levels until 1 single tile per level
    For other file formats like MRXS or SVS, any tile size is supported.

For (1), there is an improvment in Cytomine ULiege Edition (which I’m the maintainer of) that removes this limitation, but it’s not yet merged in Cytomine CE. It doesn’t work either in ULiege version because of (2) anyway. We’re working on a complety new image server that should be out in a couple of months, it will be more robust for sure.

You cannot control conversion, it is expected to be automatically triggered, but you can reproduce the conversion offline with libvips:

vips tiffsave in.tif out.tif --pyramid --tile --tile-width 256 --tile-height 256 --big-tiff

Regarding your last experiment, maybe you’re just missing to specify the tile size to 256? I still have the feeling the issue is related to the tile size not correctly parsed/converted by Cytomine.

@geektortoise, any ideas ?

Good !

It seems Cytomine CE is not reading resolution from TIF file, but I don’t know why (Cytomine-IMS/PyramidalTIFFFormat.groovy at 507e95406aca78f2ada4a5ec903cd39b50d42b8a · cytomine/Cytomine-IMS · GitHub) @geektortoise this one is for you :slight_smile:

Hi Ulysse,

Thank you for the help, very much appreciated. Formatting the files and visualizing them in Cytomine is not a problem anymore. Using the following command generates “valid” tifs:

vips tiffsave input.tif output.tif --pyramid --tile --tile-width 256 --tile-height 256 --bigtiff --compression jpeg --Q 80

However, Cytomine cannot read the resolution. I know the resolution is correct and stored in the file because ASAP and vipsheader can read it:

vipsheader -a converted.tif
converted.tif: 66000x45402 uchar, 3 bands, srgb, tiffload
width: 66000
height: 45402
bands: 3
format: uchar
coding: none
interpretation: srgb
xoffset: 0
yoffset: 0
xres: 2004.03
yres: 2004.03
filename: converted.tif
vips-loader: tiffload
n-pages: 10
resolution-unit: cm
orientation: 1

This 2004.03 resolutions means: 1 / (2004.03 / 1000) = 0.49 um/px, which is correct. This is not recognized by Cytomine. However, if I manually add the resolution in Cytomine using the “Set Calibration” button, then it works.

I wonder if this is a bug or expected behavior, and how to fix it.

Thank you!
David

Hi David,

I would use “tiffinfo” to have a look at the TIFF structure for a file where cytomine can read the resolution, and one where it cannot.

TIFF has an embarrassingly large number of ways for images to express resolution information (I can think of at least three) and I would guess that libvips is using one and Cytomine is expecting another.

A wild guess would be that libvips is using the official TIFF resolution tags, but Cytomine is expecting an XMP block.

Hello John,

Thank you for your answer. Unfortunately, I haven’t been able to find a TIF or TIFF sample file whose resolution can be automatically read by Cytomine. It would certainly help to know how Cytomine reads the resolution of these TIF images. I suspect this is a bug caused by either Cytomine or some underlying library used to read these files.

David

Oh, that’s odd. Does Cytomine let you save TIFFs?

Not that I’m aware of. I cannot properly test this issue because I don’t have any scanner producing TIF files, only SVS or MRXS. I’ve tried downloading TIF samples from the Internet but still, no luck reading the resolution with Cytomine.

I suspect that since people normally do not upload TIF files to Cytomine (they upload SVS, MRXS, etc. instead), this bug went under the radar. Hopefully we can fix it.

Here you can find a file from the Openslide project that I converted with TIF (CMU-3_converted_jpeg.tiff - Google Drive). This one can be visualized in Cytomine and works if I manually set the resolution to 0.49um/px using the “Set Calibration” option from Cytomine. Otherwise, it works fine with ASAP, vips, tiffinfo, etc.

Tiffinfo output for this file:

tiffinfo CMU-3_converted_jpeg.tif
TIFF Directory at offset 0x8565b22 (139877154)
Image Width: 66000 Image Length: 45402
Tile Width: 256 Tile Length: 256
Resolution: 20040.2, 20040.2 pixels/cm
Bits/Sample: 8
Sample Format: unsigned integer
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)
TIFF Directory at offset 0xb24aef6 (186953462)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 33000 Image Length: 22701
Tile Width: 256 Tile Length: 256
Resolution: 20040.3, 20040.3 pixels/cm
Bits/Sample: 8
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)
TIFF Directory at offset 0xbe6265a (199632474)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 16500 Image Length: 11350
Tile Width: 256 Tile Length: 256
Resolution: 20040.3, 20040.3 pixels/cm
Bits/Sample: 8
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)
TIFF Directory at offset 0xc15d8d0 (202758352)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 8250 Image Length: 5675
Tile Width: 256 Tile Length: 256
Resolution: 20040.3, 20040.3 pixels/cm
Bits/Sample: 8
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)
TIFF Directory at offset 0xc21e0fc (203546876)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 4125 Image Length: 2837
Tile Width: 256 Tile Length: 256
Resolution: 20040.3, 20040.3 pixels/cm
Bits/Sample: 8
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)
TIFF Directory at offset 0xc25029c (203752092)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 2062 Image Length: 1418
Tile Width: 256 Tile Length: 256
Resolution: 20040.3, 20040.3 pixels/cm
Bits/Sample: 8
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)
TIFF Directory at offset 0xc25e728 (203810600)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 1031 Image Length: 709
Tile Width: 256 Tile Length: 256
Resolution: 20040.3, 20040.3 pixels/cm
Bits/Sample: 8
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)
TIFF Directory at offset 0xc2636d0 (203830992)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 515 Image Length: 354
Tile Width: 256 Tile Length: 256
Resolution: 20040.3, 20040.3 pixels/cm
Bits/Sample: 8
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)
TIFF Directory at offset 0xc265516 (203838742)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 257 Image Length: 177
Tile Width: 256 Tile Length: 256
Resolution: 20040.3, 20040.3 pixels/cm
Bits/Sample: 8
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)
TIFF Directory at offset 0xc266238 (203842104)
Subfile Type: reduced-resolution image (1 = 0x1)
Image Width: 128 Image Length: 88
Tile Width: 256 Tile Length: 256
Resolution: 20040.3, 20040.3 pixels/cm
Bits/Sample: 8
Compression Scheme: JPEG
Photometric Interpretation: YCbCr
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Planar Configuration: single image plane
Reference Black/White:
0: 0 255
1: 128 255
2: 128 255
JPEG Tables: (574 bytes)

Sounds like we need help from the cytomine devs to go any further.

1 Like

Thanks John and David for the inputs !

In fact, Cytomine CE (community edition - Cytomine · GitHub) just does not read the resolution from TIFF files. It is explicitly disabled, as I explained above (Visualization problem with TIF in Cytomine - #8 by urubens), but I don’t know the reason. We need some inputs from Cytomine CE devs (like @geektortoise)

I’m one of the devs of a fork “Cytomine ULiège edition” (Cytomine ULiège · GitHub) with additional experimental features. On this version, the TIFF resolution is correctly parsed but the two Cytomine versions are currently diverging a bit and not compatible (we’re planning to resync as soon as possible, but it’s still to do).

Understood! Let’s give it some time then. I will use the “Set Calibration” option for now. Thanks for all the help!

Hello all !

Sorry for this late reply, I’ve been really busy last weeks.
Thanks @urubens for your answers ! :slight_smile:
All he said was correct.

For additional information, I’ve worked on integration of the good work made by @urubens but I have a lack of time to apply my quality checks.
I will discuss with @urubens how to speed up to offer these features in the Cytomine CE.

I will inform you about our decisions.