[Insight-users] NumericLimits::min float / int Inconsistency Workaround?

Bill Lorensen bill.lorensen at gmail.com
Thu May 21 12:25:14 EDT 2009


Geoff,

Please file a feature request in the itk bug tracker following the procedure at:

http://www.vtk.org/Wiki/ITK_Procedure_for_Contributing_Bug_Fixes

Let me know when you do it and I'll assign it to myself.

Bill

On Wed, May 20, 2009 at 9:38 PM, Geoff Topping <g_topping at hotmail.com> wrote:
>
> Hi all,
>
> I'm trying to make an itk::BinaryThresholdImageFilter with a lower bound that includes all values larger than zero.  Doing this in a generic way has proven difficult due to the inconsistency in how itk::NumericLimits reports min values for float or integer types.
>
> To clarify, this code:
>
>    std::cout << "NumericTraits float min: " << itk::NumericTraits::min() << std::endl;
>    std::cout << "NumericTraits signed short min: " << itk::NumericTraits::min() << std::endl;
>
> outputs this:
>
> NumericTraits float min: 1.17549e-38
> NumericTraits signed short min: -32768
>
> And since I'm working with signed short pixels, I can't use NumericTraits::min() to set the lower threshold for my filter (although I presumably could if I was using float pixel type).
>
>
> This issue is not unique to itk::NumericTraits, but is present in std::numeric_limits as well, for reasons that are irrelivant to this discussion.
>
>
> My question: Is there a reccommended ITK style workaround for this?
>
> I want to be able to set the lower-threshold for my filter in a generic way, so don't want to set it to constants 1 (integer), as that would be well above the minimum positive value for a float type pixel.
>
> I can't use NumericTraits to get the positive minimum value representable by the type, although NumericTraits seems to be the standard way of getting this sort of information in ITK code.
>
> I could use a separate thresholding step to get a mask image with NumericLimits::Zero for values between NumericLimits::NonpositiveMin and NumericLimits::Zero and NumericLimits::One outside that range, and then multiply my original image by this mask to get a nonnegative image, and then apply a separate threshold filter on that, but I shouldn't need to do those extra steps.
>
>
> Notably, there exist implmentations of similar functions to resolve this, including one in the Boost libraries:
>
> http://www.boost.org/doc/libs/1_38_0/libs/numeric/conversion/doc/html/boost_numericconversion/bounds___traits_class.html
>
> I'm not using any Boost code in my current programs, though.
>
>
> Is there a reason NumericTraits doesn't have a function to provide the value I need?
>
> NumericTraits does have a NonpositiveMin() function, for a similar purpose, which is implemented differently for float and integer types:
>
> static float NonpositiveMin() { return -vcl_numeric_limits::max(); }
>
> static int NonpositiveMin() { return vcl_numeric_limits::min(); }
>
>
> Thanks,
> Geoff Topping
>
>
> _________________________________________________________________
> Create a cool, new character for your Windows Live™ Messenger.
> http://go.microsoft.com/?linkid=9656621
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list