]> Creatis software - clitk.git/commitdiff
Added --transform_grid which uses input->GetDirection
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Thu, 23 Jun 2011 17:44:22 +0000 (19:44 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Thu, 23 Jun 2011 17:44:22 +0000 (19:44 +0200)
(output->GetDirection is identity) and transform matrix
to determine the output grid.

tools/clitkAffineTransform.ggo
tools/clitkAffineTransformGenericFilter.txx

index ba035367e9424b5ed1779b10c3ce4326ba774cd7..8eeb3fc3b8b6365fb1bf348905d2514b241e33e4 100644 (file)
@@ -10,6 +10,7 @@ section "I/O"
 option "input"         i       "Input image filename"            string        yes
 option "output"        o       "Output image filename"           string        yes
 option "like"          l       "Resample output this image (size, spacing,origin)"     string  no
+option "transform_grid" -       "Apply affine transform to input grid for output's"     flag    off
 
 section "Options"
 option "size"          -       "New output size if different from input"       int     no      multiple
index 5a8cfa964e144132560fbc080da28ae903c67937..c758cb2f80273b6c7576abfe04626f0adee996ff 100644 (file)
@@ -163,6 +163,33 @@ AffineTransformGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
     likeReader->SetFileName(m_ArgsInfo.like_arg);
     likeReader->Update();
     resampler->SetOutputParametersFromImage(likeReader->GetOutput());
+  } else if(m_ArgsInfo.transform_grid_flag) {
+    typename itk::Matrix<double, Dimension+1, Dimension+1> invMatrix( matrix.GetInverse() );
+    typename itk::Matrix<double, Dimension, Dimension> invRotMatrix( clitk::GetRotationalPartMatrix(invMatrix) );
+    typename itk::Vector<double,Dimension> invTrans =  clitk::GetTranslationPartMatrix(invMatrix);
+
+    // Size is converted to double, transformed and converted back to size type
+    vnl_vector<double> vnlOutputSize(Dimension);
+    for(unsigned int i=0; i< Dimension; i++) {
+      vnlOutputSize[i] = input->GetLargestPossibleRegion().GetSize()[i];
+    }
+    vnlOutputSize = invRotMatrix *
+                    input->GetDirection().GetVnlMatrix() *
+                    vnlOutputSize;
+    typename OutputImageType::SizeType outputSize;
+    for(unsigned int i=0; i< Dimension; i++) {
+      outputSize[i] = lrint(vnlOutputSize[i]);
+    }
+    resampler->SetSize( outputSize );
+    
+    // Spacing can be dictly computed in the same way
+    resampler->SetOutputSpacing ( invRotMatrix *
+                                  input->GetDirection() *
+                                  input->GetSpacing() );
+    // Origin is influenced by translation but not by direction
+    resampler->SetOutputOrigin ( invRotMatrix *
+                                 input->GetOrigin() +
+                                 invTrans );
   } else {
     //Size
     typename OutputImageType::SizeType outputSize;
@@ -170,7 +197,6 @@ AffineTransformGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
       for(unsigned int i=0; i< Dimension; i++)
         outputSize[i]=m_ArgsInfo.size_arg[i];
     } else outputSize=input->GetLargestPossibleRegion().GetSize();
-    std::cout<<"Setting the size to "<<outputSize<<"..."<<std::endl;
 
     //Spacing
     typename OutputImageType::SpacingType outputSpacing;
@@ -178,7 +204,6 @@ AffineTransformGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
       for(unsigned int i=0; i< Dimension; i++)
         outputSpacing[i]=m_ArgsInfo.spacing_arg[i];
     } else outputSpacing=input->GetSpacing();
-    std::cout<<"Setting the spacing to "<<outputSpacing<<"..."<<std::endl;
 
     //Origin
     typename OutputImageType::PointType outputOrigin;
@@ -186,7 +211,6 @@ AffineTransformGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
       for(unsigned int i=0; i< Dimension; i++)
         outputOrigin[i]=m_ArgsInfo.origin_arg[i];
     } else outputOrigin=input->GetOrigin();
-    std::cout<<"Setting the origin to "<<outputOrigin<<"..."<<std::endl;
 
     // Set
     resampler->SetSize( outputSize );
@@ -195,6 +219,12 @@ AffineTransformGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
 
   }
 
+  if (m_ArgsInfo.verbose_flag) {
+    std::cout << "Setting the output size to " << resampler->GetSize() << "..." << std::endl;
+    std::cout << "Setting the output spacing to " << resampler->GetOutputSpacing() << "..." << std::endl;
+    std::cout << "Setting the output origin to " << resampler->GetOutputOrigin() << "..." << std::endl;
+  }
+
   resampler->SetInput( input );
   resampler->SetTransform( affineTransform );
   resampler->SetInterpolator( genericInterpolator->GetInterpolatorPointer());