]> Creatis software - clitk.git/blobdiff - tools/clitkImageArithmGenericFilter.txx
Add "normalize" and "divide by a scalar"
[clitk.git] / tools / clitkImageArithmGenericFilter.txx
index f3b1d449718abdc68b8c1333d0d9ef85ee56d535..82781083f302d627e8e0f57429bf3fa5735e6b41 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "clitkImageCommon.h"
 
+#include "itkMinimumMaximumImageCalculator.h"
+
 namespace clitk
 {
 
@@ -110,6 +112,17 @@ void ImageArithmGenericFilter<args_info_type>::UpdateWithInputImageType()
   typename ImageType::Pointer input2 = NULL;
   IteratorType it2;
 
+  // Special case for normalisation
+  if (mTypeOfOperation == 12) {
+    typedef itk::MinimumMaximumImageCalculator<ImageType> MinMaxFilterType;
+    typename MinMaxFilterType::Pointer ff = MinMaxFilterType::New();
+    ff->SetImage(input1);
+    ff->ComputeMaximum();
+    mScalar = ff->GetMaximum();
+    DD(mScalar);
+    DD("normalisation");
+    mTypeOfOperation = 11; // divide
+  }
 
   if (mIsOperationUseASecondImage) {
       // Read input2
@@ -370,6 +383,13 @@ void clitk::ImageArithmGenericFilter<args_info_type>::ComputeImage(Iter1 it, Ite
       ++ito;
     }
     break;
+  case 11: // divide
+    while (!it.IsAtEnd()) {
+      ito.Set(PixelTypeDownCast<double, PixelType>((double)it.Get() / mScalar) );
+      ++it;
+      ++ito;
+    }
+    break;
   default: // error ?
     std::cerr << "ERROR : the operation number (" << mTypeOfOperation << ") is not known." << std::endl;
     exit(-1);