]> Creatis software - clitk.git/commitdiff
When resampling, keeping the same origin seems wrong because the origin
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Wed, 24 Jul 2013 11:29:54 +0000 (13:29 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Wed, 24 Jul 2013 13:10:40 +0000 (15:10 +0200)
is not the corner of the image but the center of the first pixel

itk/clitkResampleImageWithOptionsFilter.txx

index a3f88beb3db8443f08fa376da1480433f24e4051..ddaa8a077b41f2ffcf2456836c2eeb7a4f0119fc 100644 (file)
@@ -222,12 +222,19 @@ GenerateData()
     std::cout << "LastDimIsTime  = " << m_LastDimensionIsTime << std::endl;
   }
 
+  // Compute origin based on image corner
+  typename FilterType::OriginPointType origin = input->GetOrigin();
+  for(unsigned int i=0; i<OutputImageType::ImageDimension; i++) {
+    origin[i] -= 0.5 * input->GetSpacing()[i];
+    origin[i] += 0.5 * m_OutputSpacing[i];
+  }
+
   // Instance of the transform object to be passed to the resample
   // filter. By default, identity transform is applied
   filter->SetTransform(m_Transform);
   filter->SetSize(m_OutputSize);
   filter->SetOutputSpacing(m_OutputSpacing);
-  filter->SetOutputOrigin(input->GetOrigin());
+  filter->SetOutputOrigin(origin);
   filter->SetDefaultPixelValue(m_DefaultPixelValue);
   filter->SetNumberOfThreads(this->GetNumberOfThreads()); 
   filter->SetOutputDirection(input->GetDirection()); // <-- NEEDED if we want to keep orientation (in case of PermutAxes for example)