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

How can I get thumbnail image faster from Openslide Image? #168

Closed
tand826 opened this issue Apr 6, 2020 · 2 comments
Closed

How can I get thumbnail image faster from Openslide Image? #168

tand826 opened this issue Apr 6, 2020 · 2 comments
Labels

Comments

@tand826
Copy link

tand826 commented Apr 6, 2020

Hi, I'm trying to get a thumbnail from "CMU-1.ndpi"(https://data.cytomine.coop/open/openslide/hamamatsu-ndpi/CMU-1.ndpi). But it takes more than 10 seconds. Is there any other way to get a thumbnail image faster?

Sample Code

  • takes 12 seconds in average on my PC
import pyvips
import timeit
def run():
    slide = pyvips.Image.new_from_file("CMU-1.ndpi")
    thumb = slide.thumbnail_image(500)
    thumb.write_to_file("tn_CMU-1.png")

timeit.timeit(lambda :run(), number=10)

Tried

  • replace write_to_file to pngsave / jpegsave
  • from command line vipsthumbnail CMU-1.ndpi finishes within a second, but I want to implement without subprocess.call()

Environment

  • macOS 10.14.4
  • pyvips 2.1.8
  • libvips 8.8.4-Thu Dec 5 16:24:34 UTC 2019 (from brew)
@jcupitt
Copy link
Member

jcupitt commented Apr 6, 2020

Hello @tand826,

Don't use thumbnail_image. Because the image has already been opened, it can't do any of the shrink-on-load tricks that help make thumbnail fast.

Try:

import pyvips
import timeit
def run():
    slide = pyvips.Image.thumbnail("CMU-1.ndpi", 500)
    thumb.write_to_file("tn_CMU-1.png")

timeit.timeit(lambda :run(), number=10)

I would also consider updating to current libvips, 8.9.1. There have been some useful fixes.

@tand826
Copy link
Author

tand826 commented Apr 6, 2020

@jcupitt
Thank you! It works super fast!

@tand826 tand826 closed this as completed Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants