[Insight-users] Truncating floating point in SimpleITK
David Welch
david.m.welch at gmail.com
Thu Jun 27 18:10:00 EDT 2013
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/0a082e23/attachment.htm>
More information about the Insight-users
mailing list