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

Geoff Topping g_topping at hotmail.com
Thu May 21 18:04:15 EDT 2009


Hi again,

Upon further thought, the int-types requirement for NotImageFilter isn't a much of a problem as I initially thought, since the output of the BinaryThresholdImageFilter can be made an int type regardless of the type of image being thresholded (and indeed is an int type in my case).

So yes, using NotImageFilter would work in my case, and would be simpler than most alternatives.

If someone wanted the output of BinaryThresholdImageFilter to be a non-int type, though, it would be more cumbersome to use NotImageFilter, although additional steps could probably get the desired results in the desired format.

Thanks,
Geoff Topping

----------------------------------------
> From: g_topping at hotmail.com
> To: blowekamp at mail.nih.gov
> CC: insight-users at itk.org
> Subject: RE: [Insight-users] NumericLimits::min float / int Inconsistency Workaround?
> Date: Thu, 21 May 2009 17:42:36 -0400
>
>
>
> Hi Brad,
>
> Using NotImageFilter would work for integer pixel types, but not for float pixel types.
>
> From the NotImageFilter documentation: Since the logical NOT operation is only defined in C++ for integer
> types, the images passed to this filter must comply with the
> requirement of using integer pixel type.
>
>
> Geoff Topping
>
> ________________________________
>> CC: luis.ibanez at kitware.com; insight-users at itk.org
>> From: blowekamp at mail.nih.gov
>> To: g_topping at hotmail.com
>> Subject: Re: [Insight-users] NumericLimits::min float / int Inconsistency Workaround?
>> Date: Thu, 21 May 2009 09:24:39 -0400
>>
>> Geoff,
>>
>> What about using some boolean logic.
>>
>> !(NumericTraits<>::min() <= pixel <= NumericTraits<>::Zero) should be equivalent to (NumericTraits<>::Zero < pixel)
>>
>> Just use a NotImageFilter? or perhaps write a read-only NotImageAdaptor if you prefer.
>>
>> Brad
>>
>>
>>
>>
>> On May 21, 2009, at 12:00 AM, Geoff Topping wrote:
>>
>>
>> Hi again,
>>
>> It seems odd to write (and thus need to test and support) a separate specialized NonInclusiveLowerThresholdFilter when there already is a more general filter that could do the job given appropriate inputs.
>>
>> Is there a reason NumericTraits<>::PositiveMin can't / shouldn't be added? This would have applications outside the scope of my particular problem, and is a surprising omission, to me.
>>
>> If PositiveMin can't be added, I'd suggest modifying BinaryThresholdImageFilter to take optional second parameters for the SetLowerThreshold and SetUpperThreshold functions. These parameters would be bools that indicate whether the whether the threshold test should include values equal to the threshold value. The default value would be inclusive thresholds, so as to not break existing code that expects the current behaviour.
>>
>> Alternatively, new functions named something like SetLowerThresholdInclusive(bool) and SetUpperThresholdInclusive(bool) could set whether each threshold is inclusive, defaulting to the current behaviour, if default parameters are frowned upon.
>>
>> Similarly, SetUpperThresholdInclusive(), SetUpperThresholdExclusive) and equivalents for the lower threshold could work.
>>
>> I don't know if there is an established precedent elsewhere in ITK for how such situations should be handled...
>>
>> Geoff
>>
>> ----------------------------------------
>> Date: Wed, 20 May 2009 23:41:40 -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,
>>
>> Thanks for the clarifications.
>>
>> The simple option is to write your own thresholding filter.
>>
>> It is actually quite easy.
>>
>>
>> Just do the following:
>>
>> A) Copy paste the files itkBinaryThresholdImageFilter. h and txx
>>
>> B) Rename them, and rename the class inside.
>>
>> C) Modify the .h file in lines 98-105.
>>
>> Replace:
>>
>> inline TOutput operator()( const TInput & A ) const
>> {
>> if ( m_LowerThreshold <= A && A <= m_UpperThreshold )
>> {
>> return m_InsideValue;
>> }
>> return m_OutsideValue;
>> }
>>
>> with
>>
>> inline TOutput operator()( const TInput & A ) const
>> {
>> if ( m_LowerThreshold < A )
>> {
>> return m_InsideValue;
>> }
>> return m_OutsideValue;
>> }
>>
>> D) Get rid of all references to Upper threshold
>>
>>
>>
>> and once you get it to work,
>>
>>
>> We encourage you to share your new filter with the community
>> by submitting it to the Insight Journal
>>
>> http://www.insight-journal.org
>>
>>
>>
>> Regards,
>>
>>
>> Luis
>>
>>
>>
>> ---------------------
>> Geoff Topping wrote:
>> 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
>>
>> _________________________________________________________________
>> Windows Live helps you keep up with all your friends, in one place.
>> http://go.microsoft.com/?linkid=9660826
>> _____________________________________
>> 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
>>
>>
>> ========================================================
>>
>> Bradley Lowekamp
>>
>> Lockheed Martin Contractor for
>>
>> Office of High Performance Computing and Communications
>>
>> National Library of Medicine
>>
>> blowekamp at mail.nih.gov
>>
>>
>
> _________________________________________________________________
> One at a time or all at once? Get updates from your friends in one place.
> http://go.microsoft.com/?linkid=9660827

_________________________________________________________________
Find info faster and easier with Internet Explorer 8.
http://go.microsoft.com/?linkid=9655583


More information about the Insight-users mailing list