From: Romulo Pinho Date: Thu, 6 Oct 2011 15:03:06 +0000 (+0200) Subject: clitkImageStatistics - support for 4D images X-Git-Tag: v1.3.0~196^2~4 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=d8d3febb5b610a76d682c7ae9bb5d9b5bf090178;p=clitk.git clitkImageStatistics - support for 4D images - label mask may also be (n-1)D --- diff --git a/tools/clitkImageStatisticsGenericFilter.cxx b/tools/clitkImageStatisticsGenericFilter.cxx index 23cf4df..90e6ecb 100644 --- a/tools/clitkImageStatisticsGenericFilter.cxx +++ b/tools/clitkImageStatisticsGenericFilter.cxx @@ -58,6 +58,16 @@ namespace clitk std::cout << "Invalid image channel" << std::endl; return; } + + if (m_ArgsInfo.mask_given) { + int maskDimension, maskComponents; + std::string maskPixelType; + ReadImageDimensionAndPixelType(m_ArgsInfo.mask_arg, maskDimension, maskPixelType, maskComponents); + if (!(maskDimension == Dimension || maskDimension == (Dimension - 1))) { + std::cout << "Dimension of label mask must be equal to the (d)imension of the input image or d-1." << std::endl; + return; + } + } // Call UpdateWithDim diff --git a/tools/clitkImageStatisticsGenericFilter.txx b/tools/clitkImageStatisticsGenericFilter.txx index cf05bb6..9931fa0 100644 --- a/tools/clitkImageStatisticsGenericFilter.txx +++ b/tools/clitkImageStatisticsGenericFilter.txx @@ -19,6 +19,7 @@ #define clitkImageStatisticsGenericFilter_txx #include "itkNthElementImageAdaptor.h" +#include "itkJoinSeriesImageFilter.h" /* ================================================= * @file clitkImageStatisticsGenericFilter.txx @@ -28,6 +29,7 @@ * @brief * ===================================================*/ +#include "clitkImageStatisticsGenericFilter.h" namespace clitk @@ -76,8 +78,9 @@ namespace clitk { // ImageTypes + typedef unsigned char LabelPixelType; typedef itk::Image, Dimension> InputImageType; - typedef itk::Image LabelImageType; + typedef itk::Image LabelImageType; // Read the input typedef itk::ImageFileReader InputReaderType; @@ -100,11 +103,40 @@ namespace clitk // Label image typename LabelImageType::Pointer labelImage; if (m_ArgsInfo.mask_given) { - typedef itk::ImageFileReader LabelImageReaderType; - typename LabelImageReaderType::Pointer labelImageReader=LabelImageReaderType::New(); - labelImageReader->SetFileName(m_ArgsInfo.mask_arg); - labelImageReader->Update(); - labelImage= labelImageReader->GetOutput(); + 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, + // so we need to replicate the label image as many times as the size along dimension Di. + if (m_Verbose) + std::cout << "Replicating label image to match input image's dimension... " << std::endl; + + typedef itk::Image ReducedLabelImageType; + typedef itk::ImageFileReader LabelImageReaderType; + typedef itk::JoinSeriesImageFilter JoinImageFilterType; + + typename LabelImageReaderType::Pointer labelImageReader=LabelImageReaderType::New(); + labelImageReader->SetFileName(m_ArgsInfo.mask_arg); + labelImageReader->Update(); + + typename JoinImageFilterType::Pointer joinFilter = JoinImageFilterType::New(); + typename InputImageType::SizeType size = input->GetLargestPossibleRegion().GetSize(); + for (unsigned int i = 0; i < size[Dimension - 1]; i++) + joinFilter->PushBackInput(labelImageReader->GetOutput()); + + joinFilter->Update(); + labelImage = joinFilter->GetOutput(); + } + else { + typedef itk::ImageFileReader LabelImageReaderType; + typename LabelImageReaderType::Pointer labelImageReader=LabelImageReaderType::New(); + labelImageReader->SetFileName(m_ArgsInfo.mask_arg); + labelImageReader->Update(); + labelImage= labelImageReader->GetOutput(); + } + } else { labelImage=LabelImageType::New(); @@ -154,6 +186,7 @@ namespace clitk statisticsFilter->SetHistogramParameters(m_ArgsInfo.bins_arg, m_ArgsInfo.lower_arg, m_ArgsInfo.upper_arg); } statisticsFilter->Update(); + if (m_Verbose) std::cout<<"FINISHED!"; // Output if (m_Verbose) std::cout<<"N° of pixels: ";