DIPlib Documentation - ©1995-2013 Quantitative Imaging Group, Delft University of Technology.

# IndexToCoordinateWithSingletons

Convert pixel index to coordinate

## SYNOPSIS

`#include "dip_coordsindx.h"`

dip_Error dip_IndexToCoordinateWithSingletons ( index, coordinate, size, stride )

## FUNCTION

This function converts an pixel `index` of an image to a `coordinate` array. The conversion is done by calculating the modulus of the index with the `stride` and `size` arrays obtained from the image. `coordinate` has to be an allocated integer array with its size equal to the size of `stride` and `size`.

A set of macros can be used instead of this function to avoid some overhead when repeatedly converting linear indices to coordinates for the same image:

       DIP_FNR_DECLARE;   /* Declares  dip_Registry rg */

       dip_Image image;
       dip_int index;
       dip_IntegerArray coordinates;

       dip_IntegerArray size;
       dip_IntegerArray stride;

       DIP_INDEX_TO_COORDINATE_DECL( ix ); /* This macro declares variable "ix", name it whatever you want. */

       DIP_FNR_INITIALISE;

       /* ... */

       DIPXJ( dip_ImageGetDimensions( image, &size, rg ));
       DIPXJ( dip_ImageGetStride( image, &stride, rg ));

       DIP_INDEX_TO_COORDINATE_INIT( size, stride, ix, rg ); /* This macro initialises variable "ix". */

       DIPXJ( dip_IntegerArrayNew( &coordinates, stride->size, 0, rg ));

       /* Now, every time you need to obtain the coordinates for an index, do: */

       DIP_INDEX_TO_COORDINATE( index, coordinates, stride, ix );

## ARGUMENTS

Data type | Name | Description
`dip_int` | `index` | lineair index
`dip_IntegerArray` | `coordinate` | output coordinates
`dip_IntegerArray` | `size` | image size array
`dip_IntegerArray` | `stride` | stride array

## SEE ALSO

`IndexToCoordinate`, `CoordinateToIndex`