From 5ef6c777941b6e69b6229192481a7a5f88fcf9fe Mon Sep 17 00:00:00 2001 From: tbaudier Date: Thu, 16 Mar 2017 14:33:39 +0100 Subject: [PATCH] Copy the orientation matrix for clitkSplitImage For 4D Images and a splitting along the time (last) dimension only --- tools/clitkSplitImageGenericFilter.cxx | 49 +++++++++++++++++++++----- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/tools/clitkSplitImageGenericFilter.cxx b/tools/clitkSplitImageGenericFilter.cxx index 4eb00b9..a73d308 100644 --- a/tools/clitkSplitImageGenericFilter.cxx +++ b/tools/clitkSplitImageGenericFilter.cxx @@ -25,6 +25,7 @@ -------------------------------------------------------------------*/ #include "clitkSplitImageGenericFilter.h" +#include "itkChangeInformationImageFilter.h" #include //-------------------------------------------------------------------- clitk::SplitImageGenericFilter::SplitImageGenericFilter(): @@ -109,6 +110,8 @@ void clitk::SplitImageGenericFilter::UpdateWithInputImageType() filter->SetExtractionRegion(extracted_region); filter->Update(); + typedef itk::ChangeInformationImageFilter< OutputImageType > InformationFilterType; + typename ImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex(); std::string base_filename=GetOutputFilename(); unsigned int number_of_output_images=input->GetLargestPossibleRegion().GetSize()[mSplitDimension]; @@ -119,16 +122,44 @@ void clitk::SplitImageGenericFilter::UpdateWithInputImageType() extracted_region.SetIndex(index); filter->SetExtractionRegion(extracted_region); filter->Update(); - if(this->m_Png){ - PngConversion png; - SetOutputFilename(base_filename+"_"+ss.str()+".png"); - typename PngConversion::OutputPngImagePointer output; - output = png.Do(this->m_Window, this->m_Level, filter->GetOutput()); - this->template SetNextOutput::OutputPngImageType>(output); + + if (ImageType::ImageDimension == 4 && mSplitDimension == 3) //Copy the transformation matrix if the original image is a 4D image splitted along the time dimension + { + typename InformationFilterType::Pointer informationFilter = InformationFilterType::New(); + informationFilter->SetInput( filter->GetOutput() ); + typename OutputImageType::DirectionType directionOutput; + for (unsigned j=0; j<3; ++j) + for (unsigned k=0; k<3; ++k) + directionOutput[j][k] = input->GetDirection()[j][k]; + informationFilter->SetOutputDirection( directionOutput ); + informationFilter->ChangeDirectionOn(); + informationFilter->UpdateOutputInformation(); + + if(this->m_Png){ + PngConversion png; + SetOutputFilename(base_filename+"_"+ss.str()+".png"); + typename PngConversion::OutputPngImagePointer output; + output = png.Do(this->m_Window, this->m_Level, informationFilter->GetOutput()); + this->template SetNextOutput::OutputPngImageType>(output); + } + else { + SetOutputFilename(base_filename+"_"+ss.str()+".mhd"); + SetNextOutput(informationFilter->GetOutput()); + } } - else { - SetOutputFilename(base_filename+"_"+ss.str()+".mhd"); - SetNextOutput(filter->GetOutput()); + else + { + if(this->m_Png){ + PngConversion png; + SetOutputFilename(base_filename+"_"+ss.str()+".png"); + typename PngConversion::OutputPngImagePointer output; + output = png.Do(this->m_Window, this->m_Level, filter->GetOutput()); + this->template SetNextOutput::OutputPngImageType>(output); + } + else { + SetOutputFilename(base_filename+"_"+ss.str()+".mhd"); + SetNextOutput(filter->GetOutput()); + } } } } -- 2.47.1