X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkAffineTransformGenericFilter.txx;h=ef81fe2d464bc7082ed42a8f2d9ae1d5856ea3dc;hb=323952cc3c1cc5d0e4f21dd9ac74736207cc544a;hp=c758cb2f80273b6c7576abfe04626f0adee996ff;hpb=55fe2db2309025f919691272d019f395a3f1dd99;p=clitk.git diff --git a/tools/clitkAffineTransformGenericFilter.txx b/tools/clitkAffineTransformGenericFilter.txx index c758cb2..ef81fe2 100644 --- a/tools/clitkAffineTransformGenericFilter.txx +++ b/tools/clitkAffineTransformGenericFilter.txx @@ -168,7 +168,20 @@ AffineTransformGenericFilter::UpdateWithDimAndPixelType() typename itk::Matrix invRotMatrix( clitk::GetRotationalPartMatrix(invMatrix) ); typename itk::Vector invTrans = clitk::GetTranslationPartMatrix(invMatrix); - // Size is converted to double, transformed and converted back to size type + // Spacing is influenced by affine transform matrix and input direction + typename InputImageType::SpacingType outputSpacing; + outputSpacing = invRotMatrix * + input->GetDirection() * + input->GetSpacing(); + + // Origin is influenced by translation but not by input direction + typename InputImageType::PointType outputOrigin; + outputOrigin = invRotMatrix * + input->GetOrigin() + + invTrans; + + // Size is influenced by affine transform matrix and input direction + // Size is converted to double, transformed and converted back to size type. vnl_vector vnlOutputSize(Dimension); for(unsigned int i=0; i< Dimension; i++) { vnlOutputSize[i] = input->GetLargestPossibleRegion().GetSize()[i]; @@ -178,18 +191,18 @@ AffineTransformGenericFilter::UpdateWithDimAndPixelType() vnlOutputSize; typename OutputImageType::SizeType outputSize; for(unsigned int i=0; i< Dimension; i++) { + // If the size is negative, we have a flip and we must modify + // the origin and the spacing accordingly. + if(vnlOutputSize[i]<0.) { + vnlOutputSize[i] *= -1.; + outputOrigin[i] = outputOrigin[i] + outputSpacing[i] * (vnlOutputSize[i]-1); + outputSpacing[i] *= -1.; + } 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 ); + resampler->SetOutputSpacing( outputSpacing ); + resampler->SetOutputOrigin( outputOrigin ); } else { //Size typename OutputImageType::SizeType outputSize;