]> Creatis software - clitk.git/commitdiff
Added --noniimeta option to cancel metadata changes with nifti file
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 28 Mar 2017 19:12:10 +0000 (21:12 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 28 Mar 2017 19:12:10 +0000 (21:12 +0200)
format

tools/clitkImageConvert.cxx
tools/clitkImageConvert.ggo
tools/clitkImageConvertGenericFilter.cxx
tools/clitkImageConvertGenericFilter.h

index 81386821e37e62d4725748729f7f9a5883fcd66b..e54c736d99ae1d9e433204931ebb0c4f7533c9d3 100644 (file)
@@ -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);
index 6d74318e776a08770c2be3ac0ab4bbeba04a40d4..2304d50876ff0423cea4af9aadf49a54883bfa78 100644 (file)
@@ -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
index a1b28c22014d14606902cd338ceb908170edd331..1e95a7bb53ca9e29408850e90cb4c5bd82ff877f 100644 (file)
@@ -24,6 +24,7 @@
 #include "vvImageWriter.h"
 #include "itkFlipImageFilter.h"
 #include "itkGDCMImageIO.h"
+#include <itkChangeInformationImageFilter.h>
 
 #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<InputImageType>(input);
 
+    typedef itk::ChangeInformationImageFilter<InputImageType> 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<InputImageType>(input);
 
   } else {
     // "trick" to call independent versions of update according to the
index aa8b2ba64b69496ee2580bc77f3ef3383bd5542b..4f1a10031db0123b4ec7295f0ae19b6fe7dd98f5 100644 (file)
@@ -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: