openslide_get_best_level_for_downsample and numeric stability

Derek Magee D.R.Magee at
Tue Dec 13 08:52:47 EST 2016

Hi Jan,

I'm suspecting you have Aperio images (and their quirky not quite integer downsamples). Personally I don't use openslide_get_best_level_for_downsample, manually getting the levels with openslide_get_level_count<> / openslide_get_level_downsample<> and finding the closest level (or best level for a particular purpose). Why do I do this when openslide_get_best_level_for_downsample exists?.. I actually have no idea. I'm guessing at some point in the past I had exactly the issue you have and this was a workaround that worked. openslide_get_best_level_for_downsample definitely rounds down, which is kind of sensible in many use cases ..  asking for 4 and getting  4.0001 is actually lower resolution than you  wanted .. where do you draw the line? 4.1? 5?


From: openslide-users [ at] On Behalf Of Jan Hudecek via openslide-users
Sent: 13 December 2016 12:40
To: openslide-users at
Subject: openslide_get_best_level_for_downsample and numeric stability


I've noticed openslide_get_best_level_for_downsample doesn't always return the best level. I have an image with 4 levels:

{w:85655 h:42392}
{w:21413 h:10598}
{w:5353 h:2649}
{w:2676 h:1324}

So openslide_get_level_downsample for second level returns downsample value 4.0000700509036573.

When I call openslide_get_best_level_for_downsample(handle, 4) it returns 0. When I call it with 4.001 it returns 1 as expected.
I'm not sure what's best solution. Should get_best_level_for_downsample also "look" upwards - ie. if there is a level with a slightly larger downsample use it? Or should I just add epsilon (how big?) to the downsample before calling it myself?
I would like to avoid scaling the image 4x as it is a performance hit and completely unnecessary.

Jan Hudecek

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the openslide-users mailing list