From: tbaudier Date: Tue, 23 Jan 2018 14:56:59 +0000 (+0100) Subject: Add localization of max and min in clitkImageStatistics X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=996c472dd4315215c25890d6b8a9b565413352f7;p=clitk.git Add localization of max and min in clitkImageStatistics --- diff --git a/tools/clitkImageStatistics.ggo b/tools/clitkImageStatistics.ggo index 7e28e42..60d451a 100644 --- a/tools/clitkImageStatistics.ggo +++ b/tools/clitkImageStatistics.ggo @@ -4,17 +4,18 @@ version "2.0" #This tool supports multiple images on the input, or even 4D, but all images must be of the same type and dimensions. purpose "Compute statistics on an image, or on part of an image specified by a mask and label(s). The tool also supports multichannel images, which is useful, e.g., for vector fields. All channels are processed (separately) by default, but only one channel may be chosen." -option "config" - "Config file" string no -option "verbose" v "Verbose" flag off +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off -option "input" i "Input image filename" string no multiple -option "channel" c "Image channel to be used in statistics (-1 to process all channels)" int no default="-1" -option "mask" m "Mask image filename (uchar)" string no -option "label" l "Label(s) in the mask image to consider" int no multiple default="1" -option "histogram" - "Compute histogram, allows median calculation" string no -option "dvhistogram" - "Compute dose volume histogram" string no -option "bins" - "Number of histogram bins" int no default="100" -option "lower" - "Lower histogram bound" double no default="-1000" -option "upper" - "Upper histogram bound" double no default="1000" +option "input" i "Input image filename" string no multiple +option "channel" c "Image channel to be used in statistics (-1 to process all channels)" int no default="-1" +option "mask" m "Mask image filename (uchar)" string no +option "label" l "Label(s) in the mask image to consider" int no multiple default="1" +option "localize" - "With verbose, write the index coordinates of the max and min" flag off +option "histogram" - "Compute histogram, allows median calculation" string no +option "dvhistogram" - "Compute dose volume histogram" string no +option "bins" - "Number of histogram bins" int no default="100" +option "lower" - "Lower histogram bound" double no default="-1000" +option "upper" - "Upper histogram bound" double no default="1000" -option "allow_resize" r "Resize mask if different from input" flag off +option "allow_resize" r "Resize mask if different from input" flag off diff --git a/tools/clitkImageStatisticsGenericFilter.h b/tools/clitkImageStatisticsGenericFilter.h index 8544d59..26da4e4 100644 --- a/tools/clitkImageStatisticsGenericFilter.h +++ b/tools/clitkImageStatisticsGenericFilter.h @@ -61,6 +61,7 @@ namespace clitk { m_ArgsInfo=a; m_Verbose=m_ArgsInfo.verbose_flag; + m_Localize=m_ArgsInfo.localize_flag; if(m_ArgsInfo.input_given) m_InputFileName=m_ArgsInfo.input_arg[0]; @@ -98,7 +99,7 @@ namespace clitk // Data members //---------------------------------------- args_info_clitkImageStatistics m_ArgsInfo; - bool m_Verbose; + bool m_Verbose, m_Localize; std::string m_InputFileName; }; diff --git a/tools/clitkImageStatisticsGenericFilter.txx b/tools/clitkImageStatisticsGenericFilter.txx index b3eff93..82a11ab 100644 --- a/tools/clitkImageStatisticsGenericFilter.txx +++ b/tools/clitkImageStatisticsGenericFilter.txx @@ -20,6 +20,7 @@ #include "itkNthElementImageAdaptor.h" #include "itkJoinSeriesImageFilter.h" +#include "itkImageRegionConstIterator.h" #include "clitkImageStatisticsGenericFilter.h" #include "clitkCropLikeImageFilter.h" @@ -232,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 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<GetCount(label)<GetMean(label)<GetVariance(label)<GetMinimum(label)<GetMaximum(label)<GetSum(label)<