[Insight-users] NumericLimits::min float / int Inconsistency Workaround?
Geoff Topping
g_topping at hotmail.com
Wed May 20 21:38:43 EDT 2009
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
More information about the Insight-users
mailing list