[Insight-users] Truncating floating point in SimpleITK

Soubzriquet soubzriquet at gmail.com
Thu Jun 27 18:30:31 EDT 2013


If the real goal is to improve compression, you could encode them as  n bit
unsigned integers, then divide by the max val to map back to [0,1] before
interpreting as a probability.  Even if you store in a larger capacity
uint, an entropy coder will do a decent job of this.

Are you concerned only about space on disk or space in memory as well?


On Thu, Jun 27, 2013 at 6:10 PM, David Welch <david.m.welch at gmail.com>wrote:

> I'm trying to make the images more compressible by removing the unneeded
> precision.  Like I said, it was a naive approach. ;-)
>
> 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,
>
> Thanks all,
> Dave
>
> On Thu, Jun 27, 2013 at 1:03 PM, Bradley Lowekamp <brad at lowekamp.net>wrote:
>
>> Dave,
>>
>> Could it be just that you are thinking base 10 and not base 2? What do
>> other numbers look like after the tranuncation?
>>
>> On Jun 27, 2013, at 10:27 AM, David Welch <david.m.welch at gmail.com>
>> wrote:
>>
>> Hey all,
>>
>> 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:
>>
>> def truncate(image, ndigits=0):
>>     """ Truncate to the given number of digits """
>>     factor = 10 ** ndigits
>>     scaled = image * factor
>>     casted = sitk.Cast(scaled, sitk.sitkUInt32)
>>     truncated = sitk.Cast(casted, image.GetPixelIDValue()) / float(factor)
>>     return truncated
>>
>> ## Test
>> test = truncate(img, 4)
>> print img[128,188,196]
>> print test[128,188,196]
>>
>> 0.700903475285
>>
>> 0.700900018215
>>
>> What am I doing wrong?  Any ideas?
>>
>>
>> Cheers,
>>
>> Dave W.
>>
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130627/14d8b47f/attachment.htm>


More information about the Insight-users mailing list