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

M Stauffer (V) mstauff at verizon.net
Tue Mar 22 13:05:29 EDT 2011


>You should look at the non-threaded resample filter code, and 
>check if the threaded version is generating identical output.

OK, I'll do this.

>It might be better if it used ImageFunction::IsInsideBuffer() 
>instead of reimplementing those checks, and it isn't clear to 
>me it is correctly incrementing across the continuous space. 
>It doesn't seem to have the boundary calculations right.
>
>For your specific question, the continuous index version of 
>IsInsideBuffer, correctly returns whether or not a continuous 
>index is inside the image.  It accounts for the 
>half-voxel-width of continuous space along each dimension of the voxel.
>You can call: ImageFunction:IsInsideBuffer(255.0000002)
>and be sure it returns the correct answer.

Yes, it already uses this, so looks like I can rid of the
precision-truncating code altogether.

It look to me that it's incrementing across the continuous space
correctly, although I don't have lots of experience with iterating over
images. There's lots of redundant code which makes it confusing to read.
It looks to me like it would work fine with only the while block
beginning on line 748, and the blocks at lines 702, 711 & 795 can be
removed.

Cheers,
Michael 

>
>--Simon
>
>
>On 03/22/2011 11:06 AM, M Stauffer (V) wrote:
>> 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
>
>
>--
>Simon K. Warfield, Ph.D.
>Professor of Radiology
>Harvard Medical School
>Director of Radiology Research
>Director Computational Radiology Laboratory Department of 
>Radiology Children's Hospital Boston
>
>http://www.crl.med.harvard.edu
>
>Administrator:
>   Laura Alice
>   laura.alice at childrens.harvard.edu
>   617-355-2755
>
>



More information about the Insight-developers mailing list