I'm trying to make the images more compressible by removing the unneeded precision. Like I said, it was a naive approach. ;-) <br><br>I ended up using sitk.GetArrayFromImage() and numpy's around() function on the array. I was looking at the decimal module for a bit, but this was simpler. I'm still testing to see if it makes any difference,<br>
<br>Thanks all,<br>Dave<br><br><div class="gmail_quote">On Thu, Jun 27, 2013 at 1:03 PM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:brad@lowekamp.net" target="_blank">brad@lowekamp.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="auto"><div>Dave,</div><div><br></div><div>Could it be just that you are thinking base 10 and not base 2? What do other numbers look like after the tranuncation?</div><div><div><div><br>On Jun 27, 2013, at 10:27 AM, David Welch <<a href="mailto:david.m.welch@gmail.com" target="_blank">david.m.welch@gmail.com</a>> wrote:<br>
<br></div><blockquote type="cite"><div><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><div><div style="overflow:hidden;width:3px;min-height:0px"><textarea style="padding:0;width:1px;min-height:1em"></textarea></div>
</div></div><div style="display:-moz-box"><div><div><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>
</div></blockquote></div></div></div></blockquote></div><br>