From 2f2ec8277e3a56d79118afbf03e26b776acb59b9 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Fri, 3 Feb 2012 07:57:12 +0100 Subject: [PATCH] Add possibility to resize/resample mask like input image --- tools/clitkImageStatistics.cxx | 12 +------ tools/clitkImageStatistics.ggo | 2 ++ tools/clitkImageStatisticsGenericFilter.cxx | 10 ------ tools/clitkImageStatisticsGenericFilter.h | 11 ------- tools/clitkImageStatisticsGenericFilter.txx | 36 +++++++++++++++------ 5 files changed, 30 insertions(+), 41 deletions(-) diff --git a/tools/clitkImageStatistics.cxx b/tools/clitkImageStatistics.cxx index 265871f..818a88c 100644 --- a/tools/clitkImageStatistics.cxx +++ b/tools/clitkImageStatistics.cxx @@ -16,16 +16,6 @@ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ===========================================================================**/ -/* ================================================= - * @file clitkImageStatistics.cxx - * @author - * @date - * - * @brief - * - ===================================================*/ - - // clitk #include "clitkImageStatistics_ggo.h" #include "clitkIO.h" @@ -43,7 +33,7 @@ int main(int argc, char * argv[]) { clitk::ImageStatisticsGenericFilter::Pointer genericFilter=clitk::ImageStatisticsGenericFilter::New(); genericFilter->SetArgsInfo(args_info); - genericFilter->Update(); + CLITK_TRY_CATCH_EXIT(genericFilter->Update()); return EXIT_SUCCESS; }// end main diff --git a/tools/clitkImageStatistics.ggo b/tools/clitkImageStatistics.ggo index bbb127b..d2e55f3 100644 --- a/tools/clitkImageStatistics.ggo +++ b/tools/clitkImageStatistics.ggo @@ -15,3 +15,5 @@ option "histogram" - "Compute histogram, allows median calculation" 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 diff --git a/tools/clitkImageStatisticsGenericFilter.cxx b/tools/clitkImageStatisticsGenericFilter.cxx index ddfe5e0..256523c 100644 --- a/tools/clitkImageStatisticsGenericFilter.cxx +++ b/tools/clitkImageStatisticsGenericFilter.cxx @@ -18,18 +18,8 @@ #ifndef clitkImageStatisticsGenericFilter_cxx #define clitkImageStatisticsGenericFilter_cxx -/* ================================================= - * @file clitkImageStatisticsGenericFilter.cxx - * @author - * @date - * - * @brief - * - ===================================================*/ - #include "clitkImageStatisticsGenericFilter.h" - namespace clitk { diff --git a/tools/clitkImageStatisticsGenericFilter.h b/tools/clitkImageStatisticsGenericFilter.h index 6511c0e..00cfff8 100644 --- a/tools/clitkImageStatisticsGenericFilter.h +++ b/tools/clitkImageStatisticsGenericFilter.h @@ -18,16 +18,6 @@ #ifndef clitkImageStatisticsGenericFilter_h #define clitkImageStatisticsGenericFilter_h -/* ================================================= - * @file clitkImageStatisticsGenericFilter.h - * @author - * @date - * - * @brief - * - ===================================================*/ - - // clitk include #include "clitkIO.h" #include "clitkCommon.h" @@ -41,7 +31,6 @@ namespace clitk { - class ITK_EXPORT ImageStatisticsGenericFilter : public itk::LightObject { public: diff --git a/tools/clitkImageStatisticsGenericFilter.txx b/tools/clitkImageStatisticsGenericFilter.txx index d1b0d4c..81f93be 100644 --- a/tools/clitkImageStatisticsGenericFilter.txx +++ b/tools/clitkImageStatisticsGenericFilter.txx @@ -21,16 +21,9 @@ #include "itkNthElementImageAdaptor.h" #include "itkJoinSeriesImageFilter.h" -/* ================================================= - * @file clitkImageStatisticsGenericFilter.txx - * @author - * @date - * - * @brief - * - ===================================================*/ #include "clitkImageStatisticsGenericFilter.h" - +#include "clitkCropLikeImageFilter.h" +#include "clitkResampleImageWithOptionsFilter.h" namespace clitk { @@ -106,6 +99,7 @@ namespace clitk int maskDimension, maskComponents; std::string maskPixelType; ReadImageDimensionAndPixelType(m_ArgsInfo.mask_arg, maskDimension, maskPixelType, maskComponents); + if (maskDimension == Dimension - 1) { // Due to a limitation of filter itk::LabelStatisticsImageFilter, InputImageType and LabelImageType // must have the same image dimension. However, we want to support label images with Dl = Di - 1, @@ -135,6 +129,30 @@ namespace clitk labelImageReader->SetFileName(m_ArgsInfo.mask_arg); labelImageReader->Update(); labelImage= labelImageReader->GetOutput(); + + // Check mask sampling/size + if (!HaveSameSizeAndSpacing(labelImage, input)) { + if (m_ArgsInfo.allow_resize_flag) { + if (m_ArgsInfo.verbose_flag) { + std::cout << "Resize mask image like input" << std::endl; + } + typedef clitk::ResampleImageWithOptionsFilter ResamplerType; + typename ResamplerType::Pointer resampler = ResamplerType::New(); + resampler->SetInput(labelImage); + resampler->SetOutputSpacing(input->GetSpacing()); + resampler->Update(); + labelImage = resampler->GetOutput(); + + typename itk::ImageBase::RegionType reg + = input->GetLargestPossibleRegion(); + labelImage = ResizeImageLike(labelImage, ®, 0); + } + else { + std::cerr << "Mask image has a different size/spacing than input. Abort" << std::endl; + exit(-1); + } + } + } } -- 2.45.2