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

Geoff Topping g_topping at hotmail.com
Wed May 20 22:21:10 EDT 2009


Hi Luis,

If I use a lower threshold of NumericTraits::Zero, voxels with value equal to 0 are set to the inside value in the output image.

Also, the comments in itkBinaryThresholdImageFilter.h say:

 * Values equal to either threshold is considered to be between the thresholds.

Geoff Topping

----------------------------------------
> Date: Wed, 20 May 2009 22:08:52 -0400
> From: luis.ibanez at kitware.com
> To: g_topping at hotmail.com
> CC: insight-users at itk.org
> Subject: Re: [Insight-users] NumericLimits::min float / int Inconsistency Workaround?
>
>
> Hi Geoff,
>
> If what you want is to get all values larger than zero,
>
> what is wrong with using:
>
>
> UpperThreshold = NumericTraits::max()
> LowerThreshold = NumericTraits::Zero
>
> ??
>
>
> Something is contradictory in your description of
> requiremets.
>
>
>
> Luis
>
>
>
> -------------------------
> Geoff Topping 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
>>

_________________________________________________________________
One at a time or all at once? Get updates from your friends in one place.
http://go.microsoft.com/?linkid=9660827


More information about the Insight-users mailing list