Create A Index

Synopsis

Create a itk::Index, which represents a pixel location in an itk::Image.

Results

Output::

[0, 0] [1, 2]

Code

C++

#include "itkIndex.h"

int
main(int, char *[])
{
  constexpr unsigned int Dimension = 2;

  using IndexType = itk::Index<Dimension>;

  IndexType index;

  // Method 1
  // set both index[0] and index[1] to the same value (in this case, 0).
  index.Fill(0);
  std::cout << index << std::endl;

  // Method 2
  // set each component of the index individually.
  index[0] = 1;
  index[1] = 2;

  std::cout << index << std::endl;

  return EXIT_SUCCESS;
}

Python

#!/usr/bin/env python
#
# ==========================================================================*/

import itk

Dimension = 2

index = itk.Index[Dimension]()

# Method 1
# set both index[0] and index[1] to the same value (in this case, 0).
index.Fill(0)
print(index)

# Method 2
# set each component of the index individually.
index[0] = 1
index[1] = 2
print(index)

Classes demonstrated