X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkImageStatisticsGenericFilter.txx;h=f5c82356dff35c50bd2a3c841d9dc07ae820bdea;hb=61f1b1d325c260565db5ff8942826a25faf58ec4;hp=a0d2abfc609e101ece56b5b1e6606f13939f0064;hpb=d5dbd01830c8c6e6df5254432fc51eb4baec389e;p=clitk.git diff --git a/tools/clitkImageStatisticsGenericFilter.txx b/tools/clitkImageStatisticsGenericFilter.txx index a0d2abf..f5c8235 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 { @@ -57,15 +50,7 @@ namespace clitk if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; UpdateWithDimAndPixelType(); } - -// else if (PixelType == "unsigned_int"){ -// if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_int..." << std::endl; -// UpdateWithDimAndPixelType(); -// } - // else if (PixelType == "char"){ - // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; - // UpdateWithDimAndPixelType(); - // } + else if(PixelType == "double"){ if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and double..." << std::endl; UpdateWithDimAndPixelType(); @@ -114,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, @@ -143,6 +129,37 @@ 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->SetGaussianFilteringEnabled(false); + resampler->Update(); + labelImage = resampler->GetOutput(); + //writeImage(labelImage, "test1.mha"); + + typedef clitk::CropLikeImageFilter FilterType; + typename FilterType::Pointer crop = FilterType::New(); + crop->SetInput(labelImage); + crop->SetCropLikeImage(input); + crop->Update(); + labelImage = crop->GetOutput(); + //writeImage(labelImage, "test2.mha"); + + } + else { + std::cerr << "Mask image has a different size/spacing than input. Abort" << std::endl; + exit(-1); + } + } + } }