<span style="font-family:tahoma,sans-serif">Hey all, <br><br>I have some images that represent probability (values between 0.0 and 1.0) and I'd like to drop the unneeded precision from the Float32 values. Here's my naive approach:</span><br>
<br><span style="font-family:courier new,monospace"><span style="color:rgb(51,51,255)">def truncate(image, ndigits=0):<br> """ Truncate to the given number of digits """<br> factor = 10 ** ndigits<br>
scaled = image * factor<br> casted = sitk.Cast(scaled, sitk.sitkUInt32)<br> truncated = sitk.Cast(casted, image.GetPixelIDValue()) / float(factor)<br> return truncated<br><br>## Test<br>test = truncate(img, 4)<br>
print img[128,188,196]<br>print test[128,188,196]</span></span><br><div class="input_area box-flex1"><div class="CodeMirror"><div style="overflow:hidden;width:3px;height:0px"><textarea style="padding:0;width:1px;height:1em"></textarea></div>
</div></div><div style="display:-moz-box" class="output vbox"><div class="hbox output_area"><div class="box-flex1 output_subarea output_text output_stream output_stdout"><pre><span style="color:rgb(255,0,0)"><font><span style="font-family:courier new,monospace">0.700903475285<br>
0.700900018215</span></font><br><span style="color:rgb(0,0,0)"><br><span style="font-family:tahoma,sans-serif">What am I doing wrong? Any ideas?<br><br><br>Cheers, <br><br>Dave W.<br></span></span> <br></span></pre></div>
</div></div><br>