baidu-research / NCRF

Cancer metastasis detection with neural conditional random field (NCRF)
Apache License 2.0
756 stars 184 forks source link

openslide.lowlevel.OpenSlideError: TIFFRGBAImageGet failed #9

Closed Hukongtao closed 5 years ago

Hukongtao commented 6 years ago

JPEGLib: Not a JPEG file: starts with 0x00 0x00. Traceback (most recent call last): File "wsi/bin/patch_gen.py", line 48, in (args.patch_size, args.patch_size)).convert('RGB') File "/home/list-2018/.conda/envs/tensorflow/lib/python3.5/site-packages/openslide/init.py", line 223, in read_region level, size[0], size[1]) File "/home/list-2018/.conda/envs/tensorflow/lib/python3.5/site-packages/openslide/lowlevel.py", line 259, in read_region _read_region(slide, buf, x, y, level, w, h) File "/home/list-2018/.conda/envs/tensorflow/lib/python3.5/site-packages/openslide/lowlevel.py", line 196, in _check_error raise OpenSlideError(err) openslide.lowlevel.OpenSlideError: TIFFRGBAImageGet failed

Hukongtao commented 6 years ago

Someone meet the error like me?and I have check the TIFF files,not this reason

yil8 commented 6 years ago

@Hukongtao it seems there are some error with your openslide. Can you try to simply use openslide and read a region?

In [2]: slide = openslide.OpenSlide('Tumor_001.tif')

In [3]: slide.read_region((71066, 125527), 0, (256, 256)).show()
Hukongtao commented 6 years ago

@yil8 I have tried the method you told me,but it doesn't work.Actually I can generate image patches, but the program will report an error when it run the 249 line(Tumor_049.tif, 14466, 127610).So I doubt if there is a problem with the picture.I got it by BaiDu Yun

Hukongtao commented 6 years ago

@yil8 slide = openslide.Openslide('Tumor_049.tif') [m, n] =slide.dimensions slide.read_region((m,n), 0, (1024, 1024)).convert('RGB').save(hkt.jpg) I got a totally black picture!!

yil8 commented 6 years ago

@Hukongtao When you said "the method I told you didn't work", can you post the specific error message? As for

slide = openslide.Openslide('Tumor_049.tif')
[m, n] =slide.dimensions
slide.read_region((m,n), 0, (1024, 1024)).convert('RGB').save(hkt.jpg)

It is correct to return a black image, because you are reading (1024, 1024) pixels from the bottom right corner of the image, which is outside of the original WSI, and openslide will give you (0, 0, 0) pixels in return, which is black. I would recommend you go through the basic examples of openslide.

Hukongtao commented 6 years ago

@yil8 My error hint is :

INFO:root:2018-07-18 11:04:35, 100 patches generated... INFO:root:2018-07-18 11:04:56, 200 patches generated... (250, 'tumor_049', '14466', '127610', Namespace(coord_path='/home/list-2018/Documents/NCRF/coords/tumor_train.txt', level=0, num_process=5, patch_path='/home/list-2018/Documents/NCRF/PATCH_IMAGE', patch_size=768, wsi_path='/media/DATA2/list-2018/CAMELYON16/training/tumor/')) JPEGLib: Not a JPEG file: starts with 0x00 0x00. Traceback (most recent call last): File "patch_gen.py", line 48, in (args.patch_size, args.patch_size)).convert('RGB') File "/home/list-2018/.conda/envs/tensorflow/lib/python3.5/site-packages/openslide/init.py", line 223, in read_region level, size[0], size[1]) File "/home/list-2018/.conda/envs/tensorflow/lib/python3.5/site-packages/openslide/lowlevel.py", line 259, in read_region _read_region(slide, buf, x, y, level, w, h) File "/home/list-2018/.conda/envs/tensorflow/lib/python3.5/site-packages/openslide/lowlevel.py", line 196, in _check_error raise OpenSlideError(err) openslide.lowlevel.OpenSlideError: TIFFRGBAImageGet failed

I am really confused.Thanks for your reply.

yil8 commented 6 years ago

@Hukongtao can you type the following command?

ls -lh /media/DATA2/list-2018/CAMELYON16/training/tumor/

It seems your file is named tumor_049.tif, while the code assume it is named Tumor_049.tif It may just be the case that the file prefix is different.

Hukongtao commented 6 years ago

@yil8 I have used the function lower() to revise the name. As you can see, I can get some image patches. It means the image name is OK. Just the tumor_049.tif has problem. Maybe I should delete all the lines belong to tumor_049.tif in the text.

yil8 commented 6 years ago

@Hukongtao Can you post the error message for the following command:

In [1]: import openslide

In [2]: slide = openslide.OpenSlide('./Tumor_049.tif')

In [3]: slide.read_region((14466 - 384, 127610 - 384), 0, (768, 768))
Out[3]: <PIL.Image.Image image mode=RGBA size=768x768 at 0x7FA8D816A320>
Hukongtao commented 6 years ago

@yil8 import openslide slide = openslide.OpenSlide('./Tumor_049.tif') slide.read_region((14466 - 384, 127610 - 384), 0, (768, 768))

I got the error: JPEGLib: Not a JPEG file: starts with 0x00 0x00. Traceback (most recent call last): File "/home/hkt/github/NCRF/exp.py", line 6, in region = slide.read_region((14466 - 384, 127610 - 384), 0, (768, 768)) File "/home/hkt/.conda/envs/tensorflow/lib/python3.5/site-packages/openslide/init.py", line 223, in read_region level, size[0], size[1]) File "/home/hkt/.conda/envs/tensorflow/lib/python3.5/site-packages/openslide/lowlevel.py", line 259, in read_region _read_region(slide, buf, x, y, level, w, h) File "/home/hkt/.conda/envs/tensorflow/lib/python3.5/site-packages/openslide/lowlevel.py", line 196, in _check_error raise OpenSlideError(err) openslide.lowlevel.OpenSlideError: TIFFRGBAImageGet failed

yil8 commented 6 years ago

@Hukongtao Given this error message, I think it is more of a issue from openslide. I'm wondering which version did you use? OpenSlide 3.4.1 is required.

Hukongtao commented 6 years ago

@yil8 I installed openslide by pip install openslide-python,but I got the error, the version is 1.1.1. So I uninstall the version and install it once again by pip install openslide-python==1.1.0, I still got the error. I think the reason lie in the coord. when I change it to region = slide.read_region((14466 - 100, 127610 - 384), 0, (768, 768)), there is no error.

yil8 commented 6 years ago

@Hukongtao 1.1.1 is the version of openslide-python, not the version of openslide library it self. It would be great if you could confirm the version of openslide library is 3.4.1 by typing the following command:

openslide-show-properties --version
openslide-show-properties 3.4.1, using OpenSlide 3.4.1
Copyright (C) 2007-2015 Carnegie Mellon University and others

OpenSlide is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License, version 2.1.
<http://gnu.org/licenses/lgpl-2.1.html>

OpenSlide comes with NO WARRANTY, to the extent permitted by law.  See the
GNU Lesser General Public License for more details.
javadnoorb commented 5 years ago

In case this is of any use to anyone, I've encountered this with some TCGA svs files in the past. Changing the slide.read_region coordinates fixes the issue. I suspect this is caused by corrupt image metadata.

sdsy888 commented 4 years ago

In case this is of any use to anyone, I've encountered this with some TCGA svs files in the past. Changing the slide.read_region coordinates fixes the issue. I suspect this is caused by corrupt image metadata.

Hi, how do you change coordinates? Did you change the range?

javadnoorb commented 4 years ago

@sdsy888 yes. I reduced the range until it worked. It was based on trial and error

sdsy888 commented 4 years ago

@javadnoorb got it. Thank you!