[Insight-developers] Patch for some filters that don't propagate direction cosines

Peter Cech pcech at vision.ee.ethz.ch
Tue Sep 12 18:09:51 EDT 2006


Please commit it, I don't have write access to the repository. Thanks!

On Tue, Sep 12, 2006 at 12:36:30 -0500, Kent Williams wrote:
> Thanks Peter.  Will you eventually be checking this change into Insight 
> when the repository opens up, or should I?
> 
> Peter Cech wrote:
> 
> >On Tue, Sep 12, 2006 at 09:41:03 -0500, Kent Williams wrote:
> > 
> >
> >>Hans ran into an issue with itk::JoinSeriesImageFilter and 
> >>itk::ExtractImageFilter -- they did not propagate the direction cosines 
> >>from the input to the output.
> >>
> >>I have a feeling that this is also the case for a number of the other 
> >>filters -- we only notice that they don't set the output Directions when 
> >>we try to use them and they're always identity.
> >>
> >>I can write a simple template function that does the Direction Cosine 
> >>assignment between the input and output images, taking into account the 
> >>dimensionality of both -- that's what I do in-line with this patch.  
> >>Then it can be called from any filter.
> >>
> >>My question is where I would put this function:
> >>
> >>1. As a member function of itkImageBase?
> >>2. As a free-standing template function in itkImageBase?
> >>3. As a member function of itkImageToImageFilter.h
> >>4. As a free-standing ""
> >>   
> >>
> >
> >I would say 4 as it is unlikely to be used outside image filters and
> >does not depend on any member of itkImageToImageFilter. 
> >
> > 
> >
> >>5. Something else?
> >>   
> >>
> >
> >Namespace itk::ImageToImageFilterDetail
> >http://www.itk.org/Doxygen/html/namespaceitk_1_1ImageToImageFilterDetail.html
> >
> >
> >The following patch does not work:
> >
> > 
> >
> >>Index: itkExtractImageFilter.txx
> >>===================================================================
> >>RCS file: 
> >>/cvsroot/Insight/Insight/Code/BasicFilters/itkExtractImageFilter.txx,v
> >>retrieving revision 1.21
> >>diff -c -r1.21 itkExtractImageFilter.txx
> >>*** itkExtractImageFilter.txx	27 Jan 2006 17:07:07 -0000	1.21
> >>--- itkExtractImageFilter.txx	12 Sep 2006 14:40:32 -0000
> >>***************
> >>*** 200,205 ****
> >>--- 200,228 ----
> >>         }
> >>       }
> >> 
> >>+     //
> >>+     // Copy the direction cosines from the input to the output.
> >>+     // On extract the output is always smaller or equal dimension
> >>+     // as the input
> >>+     typedef typename InputImageType::DirectionType InputDirectionType;
> >>+     typedef typename OutputImageType::DirectionType OutputDirectionType;
> >>+     InputDirectionType inputDir = inputPtr->GetDirection();
> >>+     OutputDirectionType outputDir = outputPtr->GetDirection();
> >>+     unsigned inputdim = InputImageType::GetImageDimension();
> >>+     unsigned outputdim = OutputImageType::GetImageDimension();
> >>+ 
> >>+     for(unsigned i = 0; i < inputdim; i++)
> >>+       {
> >>+       for(unsigned j = 0; j < inputdim; j++)
> >>+         {
> >>+         if(j < outputdim && i < outputdim)
> >>+           {
> >>+           outputDir[i][j] = inputDir[i][j];
> >>+           }
> >>+         }
> >>+       }
> >>+     outputPtr->SetDirection(outputDir);
> >>   
> >>
> >
> >Call to outputPtr->SetDirection(...)
> >
> > 
> >
> >>+ 
> >>     // set the spacing and origin
> >>     outputPtr->SetSpacing( outputSpacing );
> >>     outputPtr->SetDirection( outputDirection );
> >>   
> >>
> >
> >Another call to outputPtr->SetDirection(...). It overwrites direction
> >with stuff prepared in an if-else block just preceding the first lines
> >of the patch.
> >
> >Anyway, this patch is computing output direction incorrectly - it
> >ignores collapsed dimensions (or assumes the are always the last ones).
> >The current code in CVS is buggy, but I think the attached patch fixes
> >it.
> >
> >Regards,
> >Peter Cech
> > 
> >
> >------------------------------------------------------------------------
> >
> >Index: itkExtractImageFilter.txx
> >===================================================================
> >RCS file: 
> >/cvsroot/Insight/Insight/Code/BasicFilters/itkExtractImageFilter.txx,v
> >retrieving revision 1.21
> >diff -u -3 -d -r1.21 itkExtractImageFilter.txx
> >--- itkExtractImageFilter.txx	27 Jan 2006 17:07:07 -0000	1.21
> >+++ itkExtractImageFilter.txx	12 Sep 2006 17:00:03 -0000
> >@@ -190,10 +190,15 @@
> >          {
> >          outputSpacing[nonZeroCount] = inputSpacing[i];
> >          outputOrigin[nonZeroCount] = inputOrigin[i];
> >+          int nonZeroCount2 = 0;
> >          for (unsigned int dim = 0; dim < OutputImageDimension; ++dim)
> >            {
> >-            outputDirection[nonZeroCount][dim] =
> >-              inputDirection[nonZeroCount][dim];
> >+            if (m_ExtractionRegion.GetSize()[dim])
> >+              {
> >+              outputDirection[nonZeroCount][nonZeroCount2] =
> >+                inputDirection[nonZeroCount][dim];
> >+              ++nonZeroCount2;
> >+              }
> >            }
> >          nonZeroCount++;
> >          }
> > 
> >


More information about the Insight-developers mailing list