]> Creatis software - clitk.git/blobdiff - tools/clitkNormalizeImageFilterGenericFilter.txx
Debug clitkNormalizeImage
[clitk.git] / tools / clitkNormalizeImageFilterGenericFilter.txx
index e6911afde54adce2a07e5a3656d18520ca235b43..fd62269988dbb8a1ede174f43f3ce116dcd4248e 100644 (file)
@@ -103,6 +103,7 @@ namespace clitk
             mask->SetRegions(input->GetLargestPossibleRegion());
             mask->SetOrigin(input->GetOrigin());
             mask->SetSpacing(input->GetSpacing());
+            mask->SetDirection(input->GetDirection());
             mask->Allocate();
             mask->FillBuffer(1);
         }
@@ -112,6 +113,7 @@ namespace clitk
         outputImage->SetRegions(input->GetLargestPossibleRegion());
         outputImage->SetOrigin(input->GetOrigin());
         outputImage->SetSpacing(input->GetSpacing());
+        outputImage->SetDirection(input->GetDirection());
         outputImage->Allocate();
         outputImage->FillBuffer(0.0);
         // Set output iterator
@@ -144,13 +146,28 @@ namespace clitk
         ito.GoToBegin();
         itm.GoToBegin();
 
+        double total = 0.0;
         while (!ito.IsAtEnd()) {
+          if(itm.Get() == 1) {
+            ito.Set(((float) it.Get() - minImg)/(maxImg-minImg));
+            total += ito.Get();
+          }
+          ++it;
+          ++ito;
+          ++itm;
+        }
+
+        // Normalisation wrt total ?
+        if (mArgsInfo.total_normalisation_flag) {
+          ito.GoToBegin();
+          itm.GoToBegin();
+          while (!ito.IsAtEnd()) {
             if(itm.Get() == 1) {
-                ito.Set(((float) it.Get() - minImg)/(maxImg-minImg));
+              ito.Set(ito.Get()/total);
             }
-            ++it;
             ++ito;
             ++itm;
+          }
         }
         //
         //