]> Creatis software - clitk.git/commitdiff
Open NVector Pixel Image as 4D Image
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Fri, 16 Sep 2016 11:10:20 +0000 (13:10 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Fri, 16 Sep 2016 11:10:20 +0000 (13:10 +0200)
common/vvImageReader.cxx
common/vvImageReader.h
common/vvImageReader.txx
tools/clitkNVectorImageTo4DImageGenericFilter.txx

index 2c094a8c3eda3cfb67e85acddafb9cceb1bf562c..bc1dd20677ee84504957991a035aad4766cbff03 100644 (file)
@@ -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);
   }
index 4348e0fac7e131f38aca7ab3d1ccb47d7851902b..4dc3f409d3d193520439e534e90e17309fdd8d98 100644 (file)
@@ -36,6 +36,8 @@ public:
   MERGEDWITHTIME,
   VECTORFIELD,
   VECTORFIELDWITHTIME,
+  VECTORPIXELIMAGE,
+  VECTORPIXELIMAGEWITHTIME,
   UNDEFINEDIMAGETYPE
   } LoadedImageType;
 
index 551e42626ba7313a84bb687f2fe8322c78d93962..d1fddfb58639143a45b4b616be5d034880e93265 100644 (file)
@@ -24,6 +24,7 @@
 #include <itkImageSeriesReader.h>
 #include <itkImageToVTKImageFilter.h>
 #include <itkFlexibleVectorCastImageFilter.h>
+#include "itkVectorImageToImageAdaptor.h"
 
 #include <vtkTransform.h>
 
@@ -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<InputImageType> ReaderType;
+    typedef itk::Image<InputPixelType, VImageDimension> OutputImageType;
+    typename ReaderType::Pointer reader = ReaderType::New();
+    reader->SetFileName(mInputFilenames[0]);
+    reader->Update();
+    typename InputImageType::Pointer input= reader->GetOutput();
+
+    typedef itk::VectorImageToImageAdaptor<InputPixelType, VImageDimension-1> 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; pixelDim<VImageDimension-1; ++pixelDim)
+    {
+      size[pixelDim]=adaptor->GetLargestPossibleRegion().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; pixelDim<input->GetNumberOfComponentsPerPixel(); ++pixelDim)
+    {
+      adaptor->SetExtractComponentIndex(pixelDim);
+
+      itk::ImageRegionIterator<InputImageType> imageIterator(input,input->GetLargestPossibleRegion());
+
+      while(!imageIterator.IsAtEnd())
+      {
+        typename OutputImageType::IndexType indexVector;
+        indexVector.Fill(0);
+        for (unsigned int indexDim=0; indexDim<VImageDimension-1; ++indexDim)
+        {
+          indexVector[indexDim]=imageIterator.GetIndex().GetElement(indexDim);
+        }
+        indexVector[VImageDimension-1]=pixelDim;
+
+        output->SetPixel(indexVector, adaptor->GetPixel(imageIterator.GetIndex()));
+        ++imageIterator;
+      }
+    }
+
+    if (VImageDimension == 4)
+      mType == VECTORPIXELIMAGEWITHTIME;
+    else
+      mType == VECTORPIXELIMAGE;
+
+    try {
+      mImage = vvImageFromITK<VImageDimension,InputPixelType>(output, mType == VECTORPIXELIMAGEWITHTIME);
+      mImage->ComputeScalarRangeBase<InputPixelType, VImageDimension>(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;
index 932b9acba309a223107b3595f686ca9ab317760b..06d5792566198e8888c753461f254de72775c595 100644 (file)
@@ -28,7 +28,6 @@
  ===================================================*/
 
 #include "itkVectorImageToImageAdaptor.h"
-#include <sstream>
 
 namespace clitk
 {