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

Johnson, Hans J hans-johnson at uiowa.edu
Mon Mar 21 17:50:58 EDT 2011


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;
>    }



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________


More information about the Insight-developers mailing list