]> Creatis software - clitk.git/blobdiff - tools/clitkImageStatisticsGenericFilter.txx
cosmetic for .ggo
[clitk.git] / tools / clitkImageStatisticsGenericFilter.txx
index 0d798e9b9ba7d76a20f4bd6899e5ef25e25ca589..82a11ab5355a86134a3a6cc666ff9136b04dc423 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "itkNthElementImageAdaptor.h"
 #include "itkJoinSeriesImageFilter.h"
+#include "itkImageRegionConstIterator.h"
 
 #include "clitkImageStatisticsGenericFilter.h"
 #include "clitkCropLikeImageFilter.h"
@@ -156,7 +157,7 @@ namespace clitk
 
           }
           else {
-            std::cerr << "Mask image has a different size/spacing than input. Abort" << std::endl;
+            std::cerr << "Mask image has a different size/spacing than input. Abort. (Use option to resize)" << std::endl;
             exit(-1);
           }
         }
@@ -170,6 +171,7 @@ namespace clitk
       labelImage->SetRegions(input->GetLargestPossibleRegion());
       labelImage->SetOrigin(input->GetOrigin());
       labelImage->SetSpacing(input->GetSpacing());
+      labelImage->SetDirection(input->GetDirection());
       labelImage->Allocate();
       labelImage->FillBuffer(m_ArgsInfo.label_arg[0]);
     }
@@ -213,7 +215,7 @@ namespace clitk
 
         std::cout<<std::endl;
         if (m_Verbose) std::cout<<"-------------"<<std::endl;
-        if (m_Verbose) std::cout<<"| Label: "<<label<<"  |"<<std::endl;
+        if (m_Verbose) std::cout<<"| Label: "<< (int) label<<"  |"<<std::endl;
         if (m_Verbose) std::cout<<"-------------"<<std::endl;
 
         // Histograms
@@ -231,8 +233,21 @@ namespace clitk
 
         statisticsFilter->Update();
 
+        //find localization for max and min (the last pixel found)
+        typename InputImageType::IndexType minIndex, maxIndex;
+        if (m_Verbose && m_Localize) {
+          itk::ImageRegionConstIterator<InputImageAdaptorType> imageIterator(input_adaptor,input_adaptor->GetLargestPossibleRegion());
+          while(!imageIterator.IsAtEnd()) {
+            if (imageIterator.Get() == statisticsFilter->GetMinimum(label))
+              minIndex = imageIterator.GetIndex();
+            if (imageIterator.Get() == statisticsFilter->GetMaximum(label))
+              maxIndex = imageIterator.GetIndex();
+            ++imageIterator;
+          }
+        }
+
         // Output
-       if (m_Verbose) std::cout<<"N° of pixels: ";
+        if (m_Verbose) std::cout<<"N° of pixels: ";
         std::cout<<statisticsFilter->GetCount(label)<<std::endl;
         if (m_Verbose) std::cout<<"Mean: ";
         std::cout<<statisticsFilter->GetMean(label)<<std::endl;
@@ -242,10 +257,20 @@ namespace clitk
         std::cout<<statisticsFilter->GetVariance(label)<<std::endl;
         if (m_Verbose) std::cout<<"Min: ";
         std::cout<<statisticsFilter->GetMinimum(label)<<std::endl;
+        if (m_Verbose && m_Localize) {
+          std::cout<<"        in voxel of index: ";
+          std::cout<<minIndex<<std::endl;
+        }
         if (m_Verbose) std::cout<<"Max: ";
         std::cout<<statisticsFilter->GetMaximum(label)<<std::endl;
+        if (m_Verbose && m_Localize) {
+          std::cout<<"        in voxel of index: ";
+          std::cout<<maxIndex<<std::endl;
+        }
         if (m_Verbose) std::cout<<"Sum: ";
         std::cout<<statisticsFilter->GetSum(label)<<std::endl;
+        if (m_Verbose) std::cout<<"Volume (cc): ";
+        std::cout<<statisticsFilter->GetCount(label)*spacing_cc<<std::endl;
         if (m_Verbose) std::cout<<"Bounding box: ";
         for(unsigned int i =0; i <statisticsFilter->GetBoundingBox(label).size(); i++)
             std::cout<<statisticsFilter->GetBoundingBox(label)[i]<<" ";