[Insight-developers] Insight-developers Digest, Vol 83, Issue 38
Simon Warfield
simon.warfield at childrens.harvard.edu
Tue Mar 22 10:15:37 EDT 2011
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
More information about the Insight-developers
mailing list