Bayer-Group / tiffslide

TiffSlide - cloud native openslide-python replacement based on tifffile
Other
84 stars 12 forks source link

tiffslide fails to detect svs format and MPP if ImageDescription contains non ascii characters #65

Closed 464hee closed 1 year ago

464hee commented 1 year ago

I have a tif file in which the mpp read using openslide is fine, but the mpp read in tiffslide is 'tiffslide.mpp-x': None, with the warning. <tifffile.TiffTag 270 @829688804> coercing invalid ASCII to bytes <tifffile.TiffTag 270 @829688804> coercing invalid ASCII to bytes

Is it because tiffslide still has some decoding deficiencies that cause it to fail to read out the mpp properly?

Here is the link to my file: https://drive.google.com/file/d/1ctw5-oxXxtXYdGXnSO-AFFcW5OuMm8eV/view?usp=share_link

464hee commented 1 year ago

@ap--

464hee commented 1 year ago

This is my code:


from tiffslide import TiffSlide
from openslide import OpenSlide
img_slide = TiffSlide('test.tif')
print(img_slide.properties)
print('-----------------------')
img_slide = OpenSlide('test.tif')
print(img_slide.properties)```
464hee commented 1 year ago

Now I have a new discovery, that is, tifffile is actually parsed, but tiffslide is not correctly obtained, about the interface between tifffile and tiffslide, can a more compatible method be used to obtain the MPP attribute, because the MPP attribute is crucial for a wsi file

464hee commented 1 year ago

new_code:

from tifffile import TiffReader with TiffReader('test.tif') as tif:
    for page in tif.pages:
        for tag in page.tags:
            tag_name, tag_value = tag.name, tag.value
            if 'MPP' in str(tag_value).upper(): 
                print(tag_name, tag_value)
<tifffile.TiffTag 270 @829688804> coercing invalid ASCII to bytes
ImageDescription b'Aperio Format Scanned By KFBIO\r\n74004x44269 [0,0 74004x44269] (256x256), JPEG/RGB Q=30|AppMag = 20|MPP = 0.484498|User = KFPBL02000110022|Time = 18:11:07|Time-Used = \x03(:.):\x8d,\x00'
ImageDescription Aperio Format Scanned By KFBIO 
37000x21504 [0,0 37000x21504] (256x256), JPEG/RGB Q=30|AppMag = 10|MPP = 0.484498
ImageDescription Aperio Format Scanned By KFBIO 
18500x10752 [0,0 18500x10752] (256x256), JPEG/RGB Q=30|AppMag = 5|MPP = 0.484498
ImageDescription Aperio Format Scanned By KFBIO 
9250x5376 [0,0 9250x5376] (256x256), JPEG/RGB Q=30|AppMag = 2|MPP = 0.484498
ImageDescription Aperio Format Scanned By KFBIO 
4625x2688 [0,0 4625x2688] (256x256), JPEG/RGB Q=30|AppMag = 1|MPP = 0.484498
ImageDescription Aperio Format Scanned By KFBIO 
2312x1344 [0,0 2312x1344] (256x256), JPEG/RGB Q=30|AppMag = 0|MPP = 0.484498
ImageDescription Aperio Format Scanned By KFBIO 
1156x672 [0,0 1156x672] (256x256), JPEG/RGB Q=30|AppMag = 0|MPP = 0.484498
ImageDescription Aperio Format Scanned By KFBIO 
578x336 [0,0 578x336] (256x256), JPEG/RGB Q=30|AppMag = 0|MPP = 0.484498
ap-- commented 1 year ago

Hi @464hee

Can you provide some additional background here? Since this seems to be a bug in the KFBIO svs export, I would initially suggest it's better to fix it there, rather then introducing compatibility code in tiffslide. That being said, I'm willing to consider support for this, but I need to understand the circumstances in more detail first.

Cheers, Andreas

464hee commented 1 year ago

Here's the thing, KFBIO has a tool to convert KFB format files to svs, most of the svs files are fine, but a few exist tiffslide can't read mpp, because the conversion code is not officially disclosed, only the conversion tool is provided, so I can't start with the conversion

464hee commented 1 year ago

Except for not reading mpp, reading images is no problem, so I tend to think tiffsilde is compatible, because tifffile and openslide can read out MPP normally for this case, and I hope tiffsilde becomes more powerful and useful.

464hee commented 1 year ago

As far as I know, KFB occupies some users in pathology images, the reason is that their scanning equipment is cheap and good, some hospitals in China have sampled the equipment for scanning to generate KFB files, but SVS is the common format, so the company provides KFB to SVS service for users, maybe they also have some problems, I personally can't communicate with the company to get changes, forgive my lack of ability

464hee commented 1 year ago

Here's the thing, KFBIO has a tool to convert KFB format files to svs, most of the svs files are fine, but a few exist tiffslide can't read mpp, because the conversion code is not officially disclosed, only the conversion tool is provided, so I can't start with the conversion

No changes can be made to the conversion code because the tool code is not publicly available

ap-- commented 1 year ago

Thank you for the information @464hee!

I contacted KFBIO and informed them about their broken converter. I'll update this issue when they reply.

I also implemented workarounds in #67. It would be great if you could test the tiffslide version in that branch, and provide me with feedback.

Cheers, Andreas

ap-- commented 1 year ago

I've merged this for now, and will prepare a new release in the next days. KFBIO is aware of the bug. So it's up to them to provide a fix. In the meantime the PR will support broken files.

Cheers, Andreas 😃