[Vv] Bug in clitkCropImage with the --like option
Benoît Presles
benoit.presles at u-bourgogne.fr
Thu Sep 26 13:59:18 CEST 2019
Dear Thomas,
A quick email just to inform you that there is a bug in the
clitkCropImage tool with the --like option. Indeed, the output image has
always an identity direction cosines matrix even if the like image does
not have an identity direction cosines matrix.
To correct the bug, I updated the itk/clitkCropLikeImageFilter.txx file
as follows:
@@ -101,14 +101,19 @@ GenerateOutputInformation() {
// Get input info
typename ImageType::SizeType likeSize;
typename ImageType::IndexType likeStart;
- typename ImageType::PointType likeOrigin;
- typename ImageType::SpacingType likeSpacing;
- if (m_LikeImage) {
+ typename ImageType::PointType likeOrigin;
+ typename ImageType::SpacingType likeSpacing;
+ typename ImageType::DirectionType likeDirection;
+ typename ImageType::DirectionType like_invDirection;
+ if (m_LikeImage) {
likeSize = m_LikeImage->GetLargestPossibleRegion().GetSize();
likeStart = m_LikeImage->GetLargestPossibleRegion().GetIndex();
likeOrigin = m_LikeImage->GetOrigin();
likeSpacing = m_LikeImage->GetSpacing();
- output->CopyInformation(m_LikeImage);
+ likeDirection = m_LikeImage->GetDirection();
+ //I don't know really why I need the inverse...
+ like_invDirection = likeDirection.GetInverse();
+ //output->CopyInformation(m_LikeImage);
}
else {
// Only load the header (allows to use 'like' with any image type)
@@ -119,7 +124,11 @@ GenerateOutputInformation() {
likeStart[i] = 0;//header->GetIORegion().GetIndex()[i];
likeOrigin[i] = header->GetOrigin(i);
likeSpacing[i] = header->GetSpacing(i);
+ for(unsigned int j=0; j<ImageType::ImageDimension; j++)
+ likeDirection[i][j] = header->GetDirection(i)[j];
}
+ //I don't know really why I need the inverse...
+ like_invDirection = likeDirection.GetInverse();
}
else {
clitkExceptionMacro("You should provide SetCropLikeFilename or
SetCropLike to CropLikeImageFilter");
@@ -150,8 +159,9 @@ GenerateOutputInformation() {
output->SetRegions(m_OutputRegion);
output->SetRequestedRegion(m_OutputRegion);
output->SetBufferedRegion(m_OutputRegion);
- output->SetSpacing(likeSpacing);
+ output->SetSpacing(likeSpacing);
output->SetOrigin(likeOrigin);
+ output->SetDirection(like_invDirection);
output->Allocate(); // Needed ?
// get startpoint source/dest
Best regards,
Ben
More information about the vv
mailing list