]> Creatis software - clitk.git/blobdiff - tools/clitkImageConvertGenericFilter.cxx
Debug clitkNormalizeImage
[clitk.git] / tools / clitkImageConvertGenericFilter.cxx
index a1b28c22014d14606902cd338ceb908170edd331..51a43a029a60fa239ebd0840465751af3198cd63 100644 (file)
@@ -24,6 +24,7 @@
 #include "vvImageWriter.h"
 #include "itkFlipImageFilter.h"
 #include "itkGDCMImageIO.h"
+#include <itkChangeInformationImageFilter.h>
 
 #include "gdcmReader.h"
 #include "gdcmAttribute.h"
@@ -147,6 +148,10 @@ void clitk::ImageConvertGenericFilter::UpdateWithInputImageType()
       // Read the attribute  Image Position (Patient)
       gdcm::Tag  DetectorInformationSequenceTag(0x0054,0x0022);
       const gdcm::DataElement & DIS = ds.GetDataElement(DetectorInformationSequenceTag);
+      if (!DIS.GetByteValue()) {
+        std::cout << "Error: could not find 0x0054,0x0022 tag. Abort." << std::endl;
+        exit(0);
+      }
       gdcm::SmartPointer<gdcm::SequenceOfItems> sqf = DIS.GetValueAsSQ();
       gdcm::Item & item = sqf->GetItem(1);
       gdcm::DataSet & ds_position = item.GetNestedDataSet();
@@ -172,8 +177,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