Create Vector Image#

Synopsis#

Create a vector image.

Results#

Output:

pixel (1,1) = [0, 0]
pixel (1,1) = [1.1, 2.2]

Code#

C++#

#include "itkVectorImage.h"

int
main()
{
  // Create an image
  using ImageType = itk::VectorImage<float, 2>;

  ImageType::IndexType start;
  start.Fill(0);

  ImageType::SizeType size;
  size.Fill(2);

  ImageType::RegionType region(start, size);

  auto image = ImageType::New();
  image->SetRegions(region);
  image->SetVectorLength(2);
  image->Allocate();

  ImageType::IndexType pixelIndex;
  pixelIndex[0] = 1;
  pixelIndex[1] = 1;

  ImageType::PixelType pixelValue = image->GetPixel(pixelIndex);

  std::cout << "pixel (1,1) = " << pixelValue << std::endl;

  using VariableVectorType = itk::VariableLengthVector<double>;
  VariableVectorType variableLengthVector;
  variableLengthVector.SetSize(2);
  variableLengthVector[0] = 1.1;
  variableLengthVector[1] = 2.2;

  image->SetPixel(pixelIndex, variableLengthVector);

  std::cout << "pixel (1,1) = " << pixelValue << std::endl;

  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TPixel, unsigned int VImageDimension = 3>
class VectorImage : public itk::ImageBase<VImageDimension>

Templated n-dimensional vector image class.

This class differs from Image in that it is intended to represent multiple images. Each pixel represents k measurements, each of datatype TPixel. The memory organization of the resulting image is as follows: … Pi0 Pi1 Pi2 Pi3 P(i+1)0 P(i+1)1 P(i+1)2 P(i+1)3 P(i+2)0 … where Pi0 represents the 0th measurement of the pixel at index i.

Conceptually, a VectorImage< TPixel, 3 > is the same as a Image< VariableLengthVector< TPixel >, 3 >. The difference lies in the memory organization. The latter results in a fragmented organization with each location in the Image holding a pointer to an VariableLengthVector holding the actual pixel. The former stores the k pixels instead of a pointer reference, which apart from avoiding fragmentation of memory also avoids storing a 8 bytes of pointer reference for each pixel. The parameter k can be set using SetVectorLength.

The API of the class is such that it returns a pixeltype VariableLengthVector< TPixel > when queried, with the data internally pointing to the buffer. (the container does not manage the memory). Similarly SetPixel calls can be made with VariableLengthVector< TPixel >.

The API of this class is similar to Image.

Caveats:

When using Iterators on this image, you cannot use the it.Value(). You must use Set/Get() methods instead.

Note

This work is part of the National Alliance for Medical Image Computing (NAMIC), funded by the National Institutes of Health through the NIH Roadmap for Medical Research, Grant U54 EB005149.

See

DefaultVectorPixelAccessor

See

DefaultVectorPixelAccessorFunctor

See

VectorImageToImagePixelAccessor

See

VectorImageToImageAdaptor

See

Image

See

ImportImageContainer

ITK Sphinx Examples:

See itk::VectorImage for additional documentation.