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

Kent Williams kent at psychiatry.uiowa.edu
Tue Sep 12 10:41:03 EDT 2006


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 ""
5. Something else?
-------------- next part --------------
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);
+ 
      // set the spacing and origin
      outputPtr->SetSpacing( outputSpacing );
      outputPtr->SetDirection( outputDirection );
Index: itkJoinSeriesImageFilter.txx
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/BasicFilters/itkJoinSeriesImageFilter.txx,v
retrieving revision 1.3
diff -c -r1.3 itkJoinSeriesImageFilter.txx
*** itkJoinSeriesImageFilter.txx	11 Jan 2006 19:43:31 -0000	1.3
--- itkJoinSeriesImageFilter.txx	12 Sep 2006 14:40:32 -0000
***************
*** 117,122 ****
--- 117,146 ----
      // set the spacing and origin
      outputPtr->SetSpacing( outputSpacing );
      outputPtr->SetOrigin( outputOrigin );
+     //
+     // Copy the direction cosines from the input to the output.
+     // On join, the output dim is always >= input dim
+     typedef typename InputImageType::DirectionType InputDirectionType;
+     typedef typename OutputImageType::DirectionType OutputDirectionType;
+     InputDirectionType inputDir = inputPtr->GetDirection();
+     unsigned int inputdim = InputImageType::GetImageDimension();
+     unsigned int outputdim = OutputImageType::GetImageDimension();
+     OutputDirectionType outputDir = outputPtr->GetDirection();
+     for(unsigned int i = 0; i < outputdim; i++)
+       {
+       for(unsigned int j = 0; j < outputdim; j++)
+         {
+         if(j < inputdim && i < inputdim)
+           {
+           outputDir[i][j] = inputDir[i][j];
+           }
+         else
+           {
+           outputDir[i][j] = i == j ? 1.0 : 0.0;
+           }
+         }
+       }
+     outputPtr->SetDirection(outputDir);
      }
    else
      {


More information about the Insight-developers mailing list