DIPlib Documentation - ©1995-2017 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_Resources 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 typeNameDescription
dip_intindexlineair index
dip_IntegerArraycoordinateoutput coordinates
dip_IntegerArraysizeimage size array
dip_IntegerArraystridestride array

SEE ALSO

IndexToCoordinate, CoordinateToIndex