[Insight-developers] precision truncation of 'delta' in ResampleImageFilter

M Stauffer (V) mstauff at verizon.net
Tue Mar 22 11:06:06 EDT 2011


Thanks Simon. Must the rounding code you mention be used explicitly, or
is it used under the hood somehow? If this delta value here ends up
yielding an index of 255.000000002 for a range of [0,255], what will
happen if it's used in, e.g., ImageFuncition::IsInsideBuffer() ?

Cheers,
Michael 

>-----Original Message-----
>From: insight-developers-bounces at itk.org 
>[mailto:insight-developers-bounces at itk.org] On Behalf Of Simon Warfield
>Sent: Tuesday, March 22, 2011 10:16 AM
>To: insight-developers at itk.org
>Subject: Re: [Insight-developers] Insight-developers Digest, 
>Vol 83, Issue 38
>
>
>This code looks like it predates the development of consistent 
>imaging bounds, voxel coordinates and interpolators.
>It looks like it works around issues that have since been resolved.
>
>In any case, the consistent voxel coordinates and 
>cross-platform rounding code that we added prior to version 
>3.20 are the way to address the concern the code comments are 
>expressing.
>
>--Simon
>
>
>On 03/22/2011 10:03 AM, insight-developers-request at itk.org wrote:
>> Date: Mon, 21 Mar 2011 21:50:58 +0000
>> From: "Johnson, Hans J"<hans-johnson at uiowa.edu>
>> Subject: Re: [Insight-developers] precision truncation of 'delta' in
>>          ResampleImageFilter
>> To: Michael Stauffer<mstauff at verizon.net>, ITK
>>          <insight-developers at itk.org>
>> Message-ID:<C9AD3259.715E%hans-johnson at uiowa.edu>
>> Content-Type: text/plain; charset="us-ascii"
>>
>> My changes were almost certainly cosmetic.  I don't 
>recognize this code.
>>
>> Hans
>>
>>
>> On 3/21/11 3:28 PM, "Michael Stauffer"<mstauff at verizon.net>  wrote:
>>
>>> Hi,
>>>
>>> I'm cleaning up ResampleImageFilter, removing redundant and 
>>> unnecessary code. I have a question about lines 637-661, 
>copied below. 'git blame'
>>> shows the code was originally from Dirk Padfield, and most recently 
>>> edited by David Cole and Hans Johnson.
>>>
>>> This code truncates values to a set precision to avoid accumulated 
>>> rouding errors while repeatedly adding a small delta. The comments 
>>> here suggest it should be truncating the 'delta' variable, but it's 
>>> operating on 'inputIndex'. As best I can understand, it should be 
>>> operating on 'delta' and not 'inputIndex'. As it stands, 'delta' 
>>> doesn't get truncated to the desired precision at all. 'inputIndex' 
>>> is initialized before this code in order to calculate delta, then 
>>> it's set again in the subsequent while loop, to what looks like the 
>>> same value in the first loop iteration, so this precision 
>adjustment here actually doesn't do anything.
>>>
>>> The code is repeated again later in the subsequent while 
>loop, where 
>>> it operates on 'inputIndex', which looks correct.
>>>
>>> Modules/Filtering/ImageGrid/include/itkResampleImageFilter.txx
>>> Lines 637-661:
>>>
>>>   // Delta is precise to many decimal points, but this precision
>>>   // involves some error in the last bits.  This error can 
>accumulate
>>>   // as the delta values are added.
>>>   // Sometimes, when the accumulated delta should be inside of the
>>>   // image, it will be slightly
>>>   // greater than the largest index in the image, like 
>255.00000000002
>>>   // for a image of size 256.  This can cause an empty 
>column to show up
>>>   // at the right side of the image. If we instead
>>>   // truncate this delta value to some precision, this 
>solves the problem.
>>>   // Therefore, the following routine uses a
>>>   // precisionConstant that specifies the number of relevant bits,
>>>   // and the value is truncated to this precision.
>>>   for ( unsigned int i = 0; i<  ImageDimension; ++i )
>>>     {
>>>     IndexValueType roundedInputIndex = (IndexValueType)( 
>inputIndex[i] );
>>>     if ( inputIndex[i]<  0.0&&  inputIndex[i] != 
>>> (double)roundedInputIndex )
>>>       {
>>>       --roundedInputIndex;
>>>       }
>>>     double inputIndexFrac = inputIndex[i] - roundedInputIndex;
>>>     double newInputIndexFrac = (IndexValueType)( precisionConstant
>>>                                        * inputIndexFrac )
>>>                                / precisionConstant;
>>>     inputIndex[i] = roundedInputIndex + newInputIndexFrac;
>>>     }
>>
>
>
>--
>Simon
>
>_______________________________________________
>Powered by www.kitware.com
>
>Visit other Kitware open-source projects at 
>http://www.kitware.com/opensource/opensource.html
>
>Kitware offers ITK Training Courses, for more information visit:
>http://kitware.com/products/protraining.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-developers



More information about the Insight-developers mailing list