From: tbaudier Date: Thu, 16 Mar 2017 14:48:54 +0000 (+0100) Subject: With clitkImageCreate, copy the transformMatrix of the mhd file X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=e87f092d3cee769263dcfd50a64191647dd4fafa;p=clitk.git With clitkImageCreate, copy the transformMatrix of the mhd file --- diff --git a/tools/clitkImageCreate.cxx b/tools/clitkImageCreate.cxx index ab2bec5..d84bbb5 100644 --- a/tools/clitkImageCreate.cxx +++ b/tools/clitkImageCreate.cxx @@ -31,23 +31,35 @@ #include "clitkIO.h" template -void NewFilledImage(int * size, float * spacing, double * origin, +void NewFilledImage(int * size, float * spacing, double * origin, double * direction, double value,typename ImageType::Pointer output) { static const unsigned int Dim = ImageType::GetImageDimension(); + typename ImageType::SizeType mSize; mSize.Fill (0); for(unsigned int i=0; iSetRegions(mRegion); output->SetSpacing(mSpacing); + output->SetDirection(directionImage); output->Allocate(); + typename ImageType::PointType mOrigin; for(unsigned int i=0; iSetOrigin(mOrigin); + typedef typename ImageType::PixelType PixelType; PixelType p = clitk::PixelTypeDownCast(value); output->FillBuffer(p); @@ -75,11 +87,15 @@ int main(int argc, char * argv[]) args_info.spacing_arg = new float[dim]; args_info.origin_given = dim; args_info.origin_arg = new double[dim]; + args_info.transformMatrix_given = dim*dim; + args_info.transformMatrix_arg = new double[dim*dim]; for(int i=0; iGetDimensions(i); args_info.spacing_arg[i] = header->GetSpacing(i); args_info.origin_arg[i]= header->GetOrigin(i); + for (int j=0; jGetDirection(i)[j]; } } @@ -119,27 +135,50 @@ int main(int argc, char * argv[]) for(int i=0; i direction; + direction.resize(dim*dim); + for(int i=0; i ImageType; ImageType::Pointer output = ImageType::New(); - NewFilledImage(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output); + NewFilledImage(args_info.size_arg, &spacing[0], &origin[0], &direction[0], args_info.value_arg, output); clitk::writeImage(output, args_info.output_arg); } if (dim == 3) { const int Dim=3; typedef itk::Image ImageType; ImageType::Pointer output = ImageType::New(); - NewFilledImage(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output); + NewFilledImage(args_info.size_arg, &spacing[0], &origin[0], &direction[0], args_info.value_arg, output); clitk::writeImage(output, args_info.output_arg); } if (dim == 4) { const int Dim=4; typedef itk::Image ImageType; ImageType::Pointer output = ImageType::New(); - NewFilledImage(args_info.size_arg, &spacing[0], &origin[0], args_info.value_arg, output); + NewFilledImage(args_info.size_arg, &spacing[0], &origin[0], &direction[0], args_info.value_arg, output); clitk::writeImage(output, args_info.output_arg); } diff --git a/tools/clitkImageCreate.ggo b/tools/clitkImageCreate.ggo index f197de7..391801d 100644 --- a/tools/clitkImageCreate.ggo +++ b/tools/clitkImageCreate.ggo @@ -11,6 +11,7 @@ option "like" l "Size/spacing like this other image" string no option "size" - "Number of pixels of each coordinate" int no multiple option "spacing" - "Spacing in mm between pixels" float no multiple option "origin" - "Origin in mm" double no multiple +option "transformMatrix" - "Rotation matrix" double no multiple option "value" - "Value for all voxels" float default="0.0" no option "verbose" v "Verbose" flag off