From ae015f09e2fa0ebc736d24b37c9ed6c1ca0cb5b2 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Thu, 15 Nov 2018 16:50:13 +0100 Subject: [PATCH] Check if mask and input have the same spacing to compute SUVPeak Before, the output of the SUVPeak was unrealistic with a mask with a spacing different from the input. Now, check if they have the same spacing. If not, the script raises an error. I add an option (--allow_resize) to automatically resize the mask according to the input like in the clitkImageStatistics script --- tools/clitkSUVPeak.ggo | 1 + tools/clitkSUVPeakGenericFilter.txx | 31 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/tools/clitkSUVPeak.ggo b/tools/clitkSUVPeak.ggo index 3aac2ae..860fae3 100644 --- a/tools/clitkSUVPeak.ggo +++ b/tools/clitkSUVPeak.ggo @@ -11,3 +11,4 @@ option "verbose" v "Verbose" flag off option "input" i "Input first image filename" string yes option "mask" m "Mask image filename (uchar)" string no +option "allow_resize" r "Resize mask if different from input" flag off diff --git a/tools/clitkSUVPeakGenericFilter.txx b/tools/clitkSUVPeakGenericFilter.txx index 498b09b..8bf1f00 100644 --- a/tools/clitkSUVPeakGenericFilter.txx +++ b/tools/clitkSUVPeakGenericFilter.txx @@ -19,6 +19,9 @@ #define CLITKSUVPEAKGENERICFILTER_TXX #include "clitkImageCommon.h" +#include "clitkCropLikeImageFilter.h" +#include "clitkResampleImageWithOptionsFilter.h" + #include namespace clitk @@ -75,6 +78,34 @@ void SUVPeakGenericFilter::UpdateWithInputImageType() typename MaskImageType::Pointer mask; if(mArgsInfo.mask_given) { mask = this->template GetInput(1); + // Check mask sampling/size + if (!HaveSameSizeAndSpacing(mask, input)) { + if (mArgsInfo.allow_resize_flag) { + if (mArgsInfo.verbose_flag) { + std::cout << "Resize mask image like input" << std::endl; + } + typedef clitk::ResampleImageWithOptionsFilter ResamplerType; + typename ResamplerType::Pointer resampler = ResamplerType::New(); + resampler->SetInput(mask); //By default the interpolation in NN, Ok for mask + resampler->SetOutputSpacing(input->GetSpacing()); + resampler->SetOutputOrigin(mask->GetOrigin()); + resampler->SetGaussianFilteringEnabled(false); + resampler->Update(); + mask = resampler->GetOutput(); + + typedef clitk::CropLikeImageFilter FilterType; + typename FilterType::Pointer crop = FilterType::New(); + crop->SetInput(mask); + crop->SetCropLikeImage(input); + crop->Update(); + mask = crop->GetOutput(); + + } + else { + std::cerr << "Mask image has a different size/spacing than input. Abort. (Use option --allow_resize)" << std::endl; + exit(-1); + } + } } else { mask = MaskImageType::New(); -- 2.45.0