libvips / pyvips

python binding for libvips using cffi
MIT License
652 stars 50 forks source link

black thumbnail of openslide image #74

Closed renexu closed 6 years ago

renexu commented 6 years ago

sample slides can be downloaded from camelyon17 dataset https://drive.google.com/file/d/0BzsdkU4jWx9BNUxvZEZyN09BYWc/view?usp=sharing

import pyvips as vips

slide = 'patient_088_node_4.tif'
image: vips.Image = vips.Image.new_from_file(slide)
thumbnail = image.thumbnail_image(image.width/32, height=image.height/32))

I can get a correct thumbnail by using openslide

import openslide
import numpy as np

slide = 'patient_088_node_4.tif'
image = openslide.open_slide(slide)
thumbnail = np.array(image.get_thumbnail([x / 32 for x in image.dimensions]))
jcupitt commented 6 years ago

Hello, I think your libvips has been built without openslide support.

I see:

$ vipsheader patient_088_node_4.tif 
patient_088_node_4.tif: 153088x95744 uchar, 4 bands, rgb, openslideload
$ vipsthumbnail patient_088_node_4.tif -s 1024x1024

tn_patient_088_node_4

renexu commented 6 years ago

you are right, mine shows tiffload. tiffload works fine for most slides, is there something specify of this one?

jcupitt commented 6 years ago

I would guess that one has been saved with jp2k compression.

Philips scanners generate tiff files that are not quite tiff files -- they add a lot of extra metadata in private tags, new compression types, new image layers, things like that. Openslide can read this extra data out, but plain libtiff cannot.

Anyway, you need to get a libvips with openslide enabled. What platform are you using? Ubuntu and RedHat at least ship libvips with openslide (I think).

jcupitt commented 6 years ago

I meant to say, if you build your own libvips, it might be worth building git master. It has an improvement to the thumbnailer that makes it much quicker with openslide images:

$ time vipsthumbnail patient_088_node_4.tif 
real    0m0.092s
user    0m0.069s
sys 0m0.013s

0.1s to thumbnail your image.

renexu commented 6 years ago

I am using MAC, reinstalled 3.7.1 with openslide, it can generate thumbnail now. The new shrink on load for openslide image is really cool, I'll try it later.

close this one for now.

Thank you