From: tbaudier Date: Fri, 16 Sep 2016 11:10:20 +0000 (+0200) Subject: Open NVector Pixel Image as 4D Image X-Git-Tag: v1.4.0~3^2~3 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=2fee636374154e8a95b481dd7a25489f2ffbb930;p=clitk.git Open NVector Pixel Image as 4D Image --- diff --git a/common/vvImageReader.cxx b/common/vvImageReader.cxx index 2c094a8..bc1dd20 100644 --- a/common/vvImageReader.cxx +++ b/common/vvImageReader.cxx @@ -60,6 +60,8 @@ void vvImageReader::Update(LoadedImageType type) reader->ReadImageInformation(); if (mInputFilenames.size() > 1) Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),type); + else if (reader->GetComponentSize() > 1 && type != VECTORFIELD && type != VECTORFIELDWITHTIME) + Update(reader->GetNumberOfDimensions()+1,reader->GetComponentTypeAsString(reader->GetComponentType()),VECTORPIXELIMAGE); else Update(reader->GetNumberOfDimensions(),reader->GetComponentTypeAsString(reader->GetComponentType()),type); } diff --git a/common/vvImageReader.h b/common/vvImageReader.h index 4348e0f..4dc3f40 100644 --- a/common/vvImageReader.h +++ b/common/vvImageReader.h @@ -36,6 +36,8 @@ public: MERGEDWITHTIME, VECTORFIELD, VECTORFIELDWITHTIME, + VECTORPIXELIMAGE, + VECTORPIXELIMAGEWITHTIME, UNDEFINEDIMAGETYPE } LoadedImageType; diff --git a/common/vvImageReader.txx b/common/vvImageReader.txx index 551e426..d1fddfb 100644 --- a/common/vvImageReader.txx +++ b/common/vvImageReader.txx @@ -24,6 +24,7 @@ #include #include #include +#include "itkVectorImageToImageAdaptor.h" #include @@ -130,6 +131,81 @@ void vvImageReader::UpdateWithDimAndInputPixelType() << "(slice #" << mSlice << ") " << err << std::endl; return; } + } else if (mType == VECTORPIXELIMAGE) { + mImage=vvImage::New(); + typedef itk::VectorImage< InputPixelType, VImageDimension-1 > InputImageType; + typedef itk::ImageFileReader ReaderType; + typedef itk::Image OutputImageType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(mInputFilenames[0]); + reader->Update(); + typename InputImageType::Pointer input= reader->GetOutput(); + + typedef itk::VectorImageToImageAdaptor ImageAdaptorType; + typename ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New(); + typename OutputImageType::Pointer output = OutputImageType::New(); + + adaptor->SetExtractComponentIndex(0); + adaptor->SetImage(input); + + //Create the output + typename OutputImageType::IndexType index; + index.Fill(0); + typename OutputImageType::SizeType size; + size.Fill(input->GetNumberOfComponentsPerPixel()); + typename OutputImageType::SpacingType spacing; + spacing.Fill(1); + typename OutputImageType::PointType origin; + origin.Fill(0); + for (unsigned int pixelDim=0; pixelDimGetLargestPossibleRegion().GetSize(pixelDim); + spacing[pixelDim]=input->GetSpacing()[pixelDim]; + origin[pixelDim]=input->GetOrigin()[pixelDim]; + } + typename OutputImageType::RegionType region; + region.SetSize(size); + region.SetIndex(index); + output->SetRegions(region); + output->SetOrigin(origin); + output->SetSpacing(spacing); + output->Allocate(); + + //Copy each channel + for (unsigned int pixelDim=0; pixelDimGetNumberOfComponentsPerPixel(); ++pixelDim) + { + adaptor->SetExtractComponentIndex(pixelDim); + + itk::ImageRegionIterator imageIterator(input,input->GetLargestPossibleRegion()); + + while(!imageIterator.IsAtEnd()) + { + typename OutputImageType::IndexType indexVector; + indexVector.Fill(0); + for (unsigned int indexDim=0; indexDimSetPixel(indexVector, adaptor->GetPixel(imageIterator.GetIndex())); + ++imageIterator; + } + } + + if (VImageDimension == 4) + mType == VECTORPIXELIMAGEWITHTIME; + else + mType == VECTORPIXELIMAGE; + + try { + mImage = vvImageFromITK(output, mType == VECTORPIXELIMAGEWITHTIME); + mImage->ComputeScalarRangeBase(output); + } catch ( itk::ExceptionObject & err ) { + std::cerr << "Error while slicing " << mInputFilenames[0].c_str() + << " " << err << std::endl; + return; + } } else { if (mInputFilenames.size() > 1) { typedef itk::Image< InputPixelType, VImageDimension > InputImageType; diff --git a/tools/clitkNVectorImageTo4DImageGenericFilter.txx b/tools/clitkNVectorImageTo4DImageGenericFilter.txx index 932b9ac..06d5792 100644 --- a/tools/clitkNVectorImageTo4DImageGenericFilter.txx +++ b/tools/clitkNVectorImageTo4DImageGenericFilter.txx @@ -28,7 +28,6 @@ ===================================================*/ #include "itkVectorImageToImageAdaptor.h" -#include namespace clitk {