View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0008275ITKpublic2008-12-09 23:152009-03-10 20:01
ReporterHans Johnson 
Assigned ToBill Lorensen 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product VersionITK-3-10 
Target VersionFixed in VersionITK-3-10 
Summary0008275: itkShrinkImageFilter does not preserve object physical locations
DescriptionI identified a bug that when using a itkMultiResolutionPyramidImageFilterTest that the center of mass of the images at the different levels was not the same.

The problem is actually in the itkShrinkImageFilter which is not preserving the center of mass of the image object.

I created a new test, ShrinkImagePreserveObjectPhysicalLocations, that tests that the center mass is preserved across all image scales.
Additional InformationI've created two pictures that helped me identify what was going on.

This will cause some other tests to fail:
    573 - itkShrinkImageTest (Failed)
    782 - itkMultiResolutionPyramidImageFilterTest (Failed)
    784 - itkRecursiveMultiResolutionPyramidImageFilterTest (Failed)
    785 - itkMultiResolutionPDEDeformableRegistrationTest (SEGFAULT)
    817 - itkDeformableTest (SEGFAULT)
    1205 - MultiResImageRegistration1Test (Failed)
    1206 - MultiResImageRegistration1Test2 (Failed)
    1207 - MultiResImageRegistration2Test (Failed)
    1208 - MultiResImageRegistration2Test2 (Failed)

I believe that these are actually "more correct" now, and may just need to have new reference images created.

TagsNo tags attached.
Resolution Date
Sprint
Sprint Status
Attached Fileszip file icon itkShrinkImageFilter_Bug_Documents.zip [^] (571,447 bytes) 2008-12-09 23:15

 Relationships
related to 0008245closedBill Lorensen ShrinkImageFilter does not stream 
related to 0008482closedkentwilliams RecursiveMultiResolutionPyramid needs to center of mass of original image 

  Notes
(0014317)
Hans Johnson (developer)
2008-12-09 23:23

PATCH THAT FIXES BUGS:

Index: Code/BasicFilters/itkShrinkImageFilter.txx
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/BasicFilters/itkShrinkImageFilter.txx,v
retrieving revision 1.54
diff -b -r1.54 itkShrinkImageFilter.txx
26a27
> #include "itkLinearInterpolateImageFunction.h"
145c146,147
< typename TInputImage::IndexType inputIndex;
---
> typedef ContinuousIndex<double, TInputImage::ImageDimension> ContinuousIndexType;
> ContinuousIndexType inputIndex;
146a149,153
> typename TOutputImage::PointType PhysicalPoint;
>
> typedef LinearInterpolateImageFunction< TInputImage, double > LinearInterpolatorType;
> typename LinearInterpolatorType::Pointer inputInterp=LinearInterpolatorType::New();
> inputInterp->SetInputImage(inputPtr);
161c168
<
---
> outputPtr->TransformIndexToPhysicalPoint(outputIndex,PhysicalPoint);
163c170
< inputIndex = outputIndex * factorSize;
---
> inputPtr->TransformPhysicalPointToContinuousIndex(PhysicalPoint,inputIndex);
166c173
< outIt.Set( inputPtr->GetPixel(inputIndex) );
---
> outIt.Set( inputInterp->EvaluateAtContinuousIndex(inputIndex) );
168d174
<
257a264,265
> const typename TInputImage::PointType&
> inputOrigin = inputPtr->GetOrigin();
263a272
> typename TOutputImage::PointType outputOrigin;
266a276,277
> typename TOutputImage::PointType::VectorType outputOriginOffset
> =outputPtr->GetDirection()*(outputSpacing-inputSpacing)*0.5;
269d279
<
277d286
<
280d288
< }
281a290,291
> outputOrigin[i]=inputOrigin[i]+outputOriginOffset[i];
> }
282a293
> outputPtr->SetOrigin ( outputOrigin );
(0014318)
Hans Johnson (developer)
2008-12-10 11:22

I feel quite strongly that an 8x8 white square in the middle of a 32x32 space should retain it's center of mass after the shrink image is applied with a shrink factor of 2,4, or 8. This is one of the test cases in the new failing test I added last night. In the current implementation, the center of mass is not preserved.

In the case of shrinking a 64x64 image to an 8x8 image, the index locations map as follows

Fill Current Proposed Object Space Preserving
Output Input Input Input ContinuousIndex
[0,0] [0,0] [4,4] [3.5,3.5]
[1,1] [8,8] [12,12] [11.5,11.5]
...
...
[7,7] [56,56] [60,60] [59.5,59.5]

By reading from the current input there is a bias towards shifting the objects towards the origin in the current implementation. Perhaps the best way to deal with this would be to add the difference between columns 3 and 4 in the table above to the origin.

* My proposed solution will need to better checking of boundary conditions (seg fault would occur on images of size 60x60 being sub-sampled to and image space of 8x8).
(0014319)
Hans Johnson (developer)
2008-12-10 11:27

On 12/10/08 9:36 AM, "Bradley Lowekamp" <blowekamp@mail.nih.gov> wrote:

Hello,

Another thing to consider is the bug I recent found: http://public.kitware.com/Bug/view.php?id=8245 [^] I believe the EnlargeOutputRequestedRegion method implemented in ShrinkImageFilter is wrong, not needed and prevents this filter from streaming. I have not had a chance to write a couple of tests though.

I have been needing a box filter shrinking image filter. I am planning on writing it shortly. The one thing I have pondered is if there is a good way to use different types of kernels when doing the resampling. I am not sure how this relates to how Hans is using the original filter, but may be useful.

The proposed patched does two thing. First it changes the filter to use a linear interpolator. I agree that this should not be added. Second it improves the calculation of the origin so that the center of the image remains the same. I think that this makes sense and should seriously be considered. For Hans' calculations it would give improved accuracy on the center of the image. I am wondering if for multi-scale registration methods if it would give additional accuracy too...

 Brad



========================================================
Bradley Lowekamp
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine
blowekamp@mail.nih.gov
(0014377)
Hans Johnson (developer)
2008-12-16 23:28

Part of this bug was addressed with changes submitted:

/cvsroot/Insight/Insight/Code/Algorithms/itkMultiResolutionPyramidImageFilter.txx,v <-- Code/Algorithms/itkMultiResolutionPyramidImageFilter.txx
new revision: 1.26;
(0014412)
Bill Lorensen (developer)
2008-12-19 23:50

The filter now uses the image transformations to ensure that the physical centers of the input and output image are the same.

The filter fix is here:
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/BasicFilters/itkShrinkImageFilter.txx?root=Insight&r1=1.54&r2=1.55&sortby=date [^]

A number of tests had to be changed to accommodate the changes to the filter. Some of these were requiring the input and output origins to be the same. This is no longer true. As mentioned above, now the centers are the same. Also some tests compared the shrink results to a true value. The algorithm to compute the true value from the input was modified to match the new output sampling technique.

http://public.kitware.com/cgi-bin/viewcvs.cgi/Testing/Code/BasicFilters/itkStreamingImageFilterTest.cxx?root=Insight&r1=1.9&r2=1.10&sortby=date [^]

http://public.kitware.com/cgi-bin/viewcvs.cgi/Testing/Code/BasicFilters/itkStreamingImageFilterTest2.cxx?root=Insight&r1=1.7&r2=1.8&sortby=date [^]

http://public.kitware.com/cgi-bin/viewcvs.cgi/Testing/Code/BasicFilters/itkShrinkImageTest.cxx?root=Insight&r1=1.31&r2=1.32&sortby=date [^]

http://public.kitware.com/cgi-bin/viewcvs.cgi/Testing/Code/Algorithms/itkRecursiveMultiResolutionPyramidImageFilterTest.cxx?root=Insight&r1=1.16&r2=1.17&sortby=date [^]

Thanks to Hans Johnson for reporting the problem and providing a good test.
(0015630)
Hans Johnson (developer)
2009-03-10 20:01

Shrink image filter has been fixed By Bill Lorensen

 Issue History
Date Modified Username Field Change
2008-12-09 23:15 Hans Johnson New Issue
2008-12-09 23:15 Hans Johnson File Added: itkShrinkImageFilter_Bug_Documents.zip
2008-12-09 23:16 Hans Johnson Status new => assigned
2008-12-09 23:16 Hans Johnson Assigned To => Luis Ibanez
2008-12-09 23:23 Hans Johnson Note Added: 0014317
2008-12-10 11:22 Hans Johnson Note Added: 0014318
2008-12-10 11:26 Hans Johnson Relationship added related to 0008245
2008-12-10 11:27 Hans Johnson Note Added: 0014319
2008-12-11 23:38 Bill Lorensen Assigned To Luis Ibanez => Bill Lorensen
2008-12-16 23:28 Hans Johnson Note Added: 0014377
2008-12-19 23:50 Bill Lorensen Note Added: 0014412
2008-12-19 23:50 Bill Lorensen Status assigned => resolved
2008-12-19 23:50 Bill Lorensen Resolution open => fixed
2009-02-07 16:58 Hans Johnson Relationship added related to 0008482
2009-03-10 20:01 Hans Johnson Note Added: 0015630
2009-03-10 20:01 Hans Johnson Status resolved => closed
2009-03-10 20:01 Hans Johnson Fixed in Version => ITK-3-10


Copyright © 2000 - 2018 MantisBT Team