/*=========================================================================
Program: vv http://www.creatis.insa-lyon.fr/rio/vv
/*=========================================================================
Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- University of LYON http://www.universite-lyon.fr/
- Léon Bérard cancer center http://www.centreleonberard.fr
- CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
- University of LYON http://www.universite-lyon.fr/
- Léon Bérard cancer center http://www.centreleonberard.fr
- CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
// Update with the number of dimensions
//-------------------------------------------------------------------
template<unsigned int Dimension, unsigned int Components>
// Update with the number of dimensions
//-------------------------------------------------------------------
template<unsigned int Dimension, unsigned int Components>
ImageStatisticsGenericFilter::UpdateWithDim(std::string PixelType)
{
if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<" with " << Components << " channel(s)..."<<std::endl;
ImageStatisticsGenericFilter::UpdateWithDim(std::string PixelType)
{
if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<" with " << Components << " channel(s)..."<<std::endl;
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
UpdateWithDimAndPixelType<Dimension, unsigned char, Components>();
}
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
UpdateWithDimAndPixelType<Dimension, unsigned char, Components>();
}
//-------------------------------------------------------------------
// Update with the number of dimensions and the pixeltype
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Update with the number of dimensions and the pixeltype
//-------------------------------------------------------------------
typedef unsigned char LabelPixelType;
typedef itk::Image<itk::Vector<PixelType, Components>, Dimension> InputImageType;
typedef itk::Image<LabelPixelType, Dimension> LabelImageType;
typedef unsigned char LabelPixelType;
typedef itk::Image<itk::Vector<PixelType, Components>, Dimension> InputImageType;
typedef itk::Image<LabelPixelType, Dimension> LabelImageType;
// Read the input
typedef itk::ImageFileReader<InputImageType> InputReaderType;
typename InputReaderType::Pointer reader = InputReaderType::New();
reader->SetFileName( m_InputFileName);
reader->Update();
typename InputImageType::Pointer input= reader->GetOutput();
// Read the input
typedef itk::ImageFileReader<InputImageType> InputReaderType;
typename InputReaderType::Pointer reader = InputReaderType::New();
reader->SetFileName( m_InputFileName);
reader->Update();
typename InputImageType::Pointer input= reader->GetOutput();
typedef itk::NthElementImageAdaptor<InputImageType, PixelType> InputImageAdaptorType;
typedef itk::Image<PixelType, Dimension> OutputImageType;
typename InputImageAdaptorType::Pointer input_adaptor = InputImageAdaptorType::New();
input_adaptor->SetImage(input);
typedef itk::NthElementImageAdaptor<InputImageType, PixelType> InputImageAdaptorType;
typedef itk::Image<PixelType, Dimension> OutputImageType;
typename InputImageAdaptorType::Pointer input_adaptor = InputImageAdaptorType::New();
input_adaptor->SetImage(input);
// Filter
typedef itk::LabelStatisticsImageFilter<InputImageAdaptorType, LabelImageType> StatisticsImageFilterType;
typename StatisticsImageFilterType::Pointer statisticsFilter=StatisticsImageFilterType::New();
// Filter
typedef itk::LabelStatisticsImageFilter<InputImageAdaptorType, LabelImageType> StatisticsImageFilterType;
typename StatisticsImageFilterType::Pointer statisticsFilter=StatisticsImageFilterType::New();
// 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.
// 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.
typedef itk::Image<LabelPixelType, Dimension - 1> ReducedLabelImageType;
typedef itk::ImageFileReader<ReducedLabelImageType> LabelImageReaderType;
typedef itk::JoinSeriesImageFilter<ReducedLabelImageType, LabelImageType> JoinImageFilterType;
typedef itk::Image<LabelPixelType, Dimension - 1> ReducedLabelImageType;
typedef itk::ImageFileReader<ReducedLabelImageType> LabelImageReaderType;
typedef itk::JoinSeriesImageFilter<ReducedLabelImageType, LabelImageType> JoinImageFilterType;
typename LabelImageReaderType::Pointer labelImageReader=LabelImageReaderType::New();
labelImageReader->SetFileName(m_ArgsInfo.mask_arg);
labelImageReader->Update();
typename LabelImageReaderType::Pointer labelImageReader=LabelImageReaderType::New();
labelImageReader->SetFileName(m_ArgsInfo.mask_arg);
labelImageReader->Update();
typename InputImageType::SizeType size = input->GetLargestPossibleRegion().GetSize();
for (unsigned int i = 0; i < size[Dimension - 1]; i++)
joinFilter->PushBackInput(labelImageReader->GetOutput());
typename InputImageType::SizeType size = input->GetLargestPossibleRegion().GetSize();
for (unsigned int i = 0; i < size[Dimension - 1]; i++)
joinFilter->PushBackInput(labelImageReader->GetOutput());
typename ResamplerType::Pointer resampler = ResamplerType::New();
resampler->SetInput(labelImage);
resampler->SetOutputSpacing(input->GetSpacing());
typename ResamplerType::Pointer resampler = ResamplerType::New();
resampler->SetInput(labelImage);
resampler->SetOutputSpacing(input->GetSpacing());
resampler->SetGaussianFilteringEnabled(false);
resampler->Update();
labelImage = resampler->GetOutput();
//writeImage<LabelImageType>(labelImage, "test1.mha");
resampler->SetGaussianFilteringEnabled(false);
resampler->Update();
labelImage = resampler->GetOutput();
//writeImage<LabelImageType>(labelImage, "test1.mha");
typedef clitk::CropLikeImageFilter<LabelImageType> FilterType;
typename FilterType::Pointer crop = FilterType::New();
crop->SetInput(labelImage);
crop->SetCropLikeImage(input);
crop->Update();
typedef clitk::CropLikeImageFilter<LabelImageType> FilterType;
typename FilterType::Pointer crop = FilterType::New();
crop->SetInput(labelImage);
crop->SetCropLikeImage(input);
crop->Update();
labelImage=LabelImageType::New();
labelImage->SetRegions(input->GetLargestPossibleRegion());
labelImage->SetOrigin(input->GetOrigin());
labelImage=LabelImageType::New();
labelImage->SetRegions(input->GetLargestPossibleRegion());
labelImage->SetOrigin(input->GetOrigin());
unsigned int firstComponent = 0, lastComponent = 0;
if (m_ArgsInfo.channel_arg == -1) {
unsigned int firstComponent = 0, lastComponent = 0;
if (m_ArgsInfo.channel_arg == -1) {
lastComponent = Components - 1;
}
else {
firstComponent = m_ArgsInfo.channel_arg;
lastComponent = m_ArgsInfo.channel_arg;
}
lastComponent = Components - 1;
}
else {
firstComponent = m_ArgsInfo.channel_arg;
lastComponent = m_ArgsInfo.channel_arg;
}
for (unsigned int c=firstComponent; c<=lastComponent; c++) {
if (m_Verbose) std::cout << std::endl << "Processing channel " << c << std::endl;
for (unsigned int c=firstComponent; c<=lastComponent; c++) {
if (m_Verbose) std::cout << std::endl << "Processing channel " << c << std::endl;
for(unsigned int i =0; i <statisticsFilter->GetBoundingBox(label).size(); i++)
std::cout<<statisticsFilter->GetBoundingBox(label)[i]<<" ";
std::cout<<std::endl;
for(unsigned int i =0; i <statisticsFilter->GetBoundingBox(label).size(); i++)
std::cout<<statisticsFilter->GetBoundingBox(label)[i]<<" ";
std::cout<<std::endl;