From: Simon Rit Date: Tue, 28 Mar 2017 19:12:10 +0000 (+0200) Subject: Added --noniimeta option to cancel metadata changes with nifti file X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=0f37ab5e1cac647d3bde50be8e170fd94558e3f2;p=clitk.git Added --noniimeta option to cancel metadata changes with nifti file format --- diff --git a/tools/clitkImageConvert.cxx b/tools/clitkImageConvert.cxx index 8138682..e54c736 100644 --- a/tools/clitkImageConvert.cxx +++ b/tools/clitkImageConvert.cxx @@ -68,6 +68,7 @@ int main(int argc, char * argv[]) filter->SetIOVerbose(args_info.verbose_flag); filter->SetOutputFilename(output); filter->SetVV(args_info.vv_flag); + filter->SetNoNiiMeta(args_info.noniimeta_flag); filter->SetCorrectNegativeSpacingFlag(args_info.correct_flag); filter->EnableWriteCompression(args_info.compression_flag); if (args_info.type_given) filter->SetOutputPixelType(args_info.type_arg); diff --git a/tools/clitkImageConvert.ggo b/tools/clitkImageConvert.ggo index 6d74318..2304d50 100644 --- a/tools/clitkImageConvert.ggo +++ b/tools/clitkImageConvert.ggo @@ -3,11 +3,12 @@ package "clitkImageConvert" version "1.0" purpose "Convert an image into another image.\n\tAllow to change the file format and/or the pixel type. \n\tKnown file formats 2D: jpeg png bmp tif mhd hdr vox dcm \n\tKnown file formats 3D: mhd vox hdr dcm\n\tKnown file formats 4D: mhd \n\tKnown images: 2D 3D or 4D, schar, uchar, short, ushort, int, float and double\n\nIf the -o option is not given, the last parameter of the command line is used as output." -option "config" - "Config file" string no -option "input" i "Input image filename" string no -option "output" o "Output image filename" string no -option "type" t "Output type (float, ushort ...)" string no -option "verbose" v "Verbose" flag off -option "compression" c "Compress output" flag off -option "vv" - "Read image as in vv and save transform in meta information" flag off -option "correct" - "Correct dicom with negative Z spacing" flag off +option "config" - "Config file" string no +option "input" i "Input image filename" string no +option "output" o "Output image filename" string no +option "type" t "Output type (float, ushort ...)" string no +option "verbose" v "Verbose" flag off +option "compression" c "Compress output" flag off +option "vv" - "Read image as in vv and save transform in meta information" flag off +option "correct" - "Correct dicom with negative Z spacing" flag off +option "noniimeta" - "Multiply 1st and 2nd coordinate of Direction and Origin by -1" flag off diff --git a/tools/clitkImageConvertGenericFilter.cxx b/tools/clitkImageConvertGenericFilter.cxx index a1b28c2..1e95a7b 100644 --- a/tools/clitkImageConvertGenericFilter.cxx +++ b/tools/clitkImageConvertGenericFilter.cxx @@ -24,6 +24,7 @@ #include "vvImageWriter.h" #include "itkFlipImageFilter.h" #include "itkGDCMImageIO.h" +#include #include "gdcmReader.h" #include "gdcmAttribute.h" @@ -172,8 +173,26 @@ void clitk::ImageConvertGenericFilter::UpdateWithInputImageType() itk::MetaDataDictionary dict;// = new itk::MetaDataDictionary; input->SetMetaDataDictionary(dict); } - this->SetNextOutput(input); + typedef itk::ChangeInformationImageFilter CIType; + typename CIType::Pointer changeInfo = CIType::New(); + if(mNoNiiMeta) { + changeInfo->SetInput(input); + typename CIType::PointType o = input->GetOrigin(); + o[0] *= -1.; + o[1] *= -1.; + typename CIType::DirectionType d = input->GetDirection(); + d[0][0] *= -1.; + d[1][1] *= -1.; + changeInfo->ChangeDirectionOn(); + changeInfo->ChangeOriginOn(); + changeInfo->SetOutputOrigin(o); + changeInfo->SetOutputDirection(d); + changeInfo->Update(); + input = changeInfo->GetOutput(); + } + + this->SetNextOutput(input); } else { // "trick" to call independent versions of update according to the diff --git a/tools/clitkImageConvertGenericFilter.h b/tools/clitkImageConvertGenericFilter.h index aa8b2ba..4f1a100 100644 --- a/tools/clitkImageConvertGenericFilter.h +++ b/tools/clitkImageConvertGenericFilter.h @@ -74,6 +74,7 @@ namespace clitk { std::string GetOutputPixelTypeName() { return mOutputPixelTypeName; } void SetOutputPixelType(std::string p) { mOutputPixelTypeName = p; } void SetVV(bool b) { mVV = b; } + void SetNoNiiMeta(bool b) { mNoNiiMeta = b; } bool IsWarningOccur() { return mWarningOccur; } std::string & GetWarning() { return mWarning; } void EnableDisplayWarning(bool b) { mDisplayWarning = b; } @@ -95,6 +96,7 @@ namespace clitk { bool mWarningOccur; bool mDisplayWarning; bool mVV; + bool mNoNiiMeta; bool mCorrectNegativeSpacingFlag; private: