<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        mso-fareast-language:EN-US;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Hi Jan,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I’m suspecting you have Aperio images (and their quirky not quite integer downsamples). Personally I don’t use
</span><span lang="EN-US">openslide_get_best_level_for_downsample, manually getting the levels with
</span><a href="http://openslide.org/api/openslide_8h.html#a19eedd09aef2bd65db7e3b0a44e54738">openslide_get_level_count</a>
<span lang="EN-US">/</span><span lang="EN-US"> </span><a href="http://openslide.org/api/openslide_8h.html#a60daced5880dc3e4cf428dd81ba67bee">openslide_get_level_downsample</a>
<span lang="EN-US">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?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">D.</span><span style="color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="color:#1F497D"><o:p> </o:p></span></a></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-GB">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:EN-GB"> openslide-users
 [mailto:openslide-users-bounces+d.r.magee=leeds.ac.uk@lists.andrew.cmu.edu] <b>On Behalf Of
</b>Jan Hudecek via openslide-users<br>
<b>Sent:</b> 13 December 2016 12:40<br>
<b>To:</b> openslide-users@lists.andrew.cmu.edu<br>
<b>Subject:</b> openslide_get_best_level_for_downsample and numeric stability<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I’ve noticed openslide_get_best_level_for_downsample doesn’t always return the best level. I have an image with 4 levels:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">{w:85655 h:42392}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">{w:21413 h:10598}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">{w:5353 h:2649}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">{w:2676 h:1324}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">So openslide_get_level_downsample for second level returns downsample value 4.0000700509036573.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">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?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I would like to avoid scaling the image 4x as it is a performance hit and completely unnecessary.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:NL">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:NL">Jan Hudecek</span><u><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial","sans-serif";color:blue;mso-fareast-language:NL"><o:p></o:p></span></u></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
</body>
</html>