Create Vector Image#

Synopsis#

Create a vector image.

operation.png

How the image whose pixels are of vector type can be set using a VariableLengthVector at runtime

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{};

  auto size = ImageType::SizeType::Filled(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<3>

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.

See also

DefaultVectorPixelAccessor

See also

DefaultVectorPixelAccessorFunctor

See also

VectorImageToImagePixelAccessor

See also

VectorImageToImageAdaptor

See also

Image

See also

ImportImageContainer

Caveats:

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

ITK Sphinx Examples:

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 itk::VectorImage for additional documentation.