pink26 0.1.1
Image processing and digital topology for teaching
Loading...
Searching...
No Matches
neighbors.h File Reference

Neighborhoods of digital topology on the square and cubic grids. More...

#include <pink26/image.h>

Go to the source code of this file.

Data Structures

struct  p26_neighborhood
 The neighbors of a pixel for one connectivity and one image geometry. More...

Enumerations

enum  { P26_NEIGHBORS_2D_MAX = 8 , P26_NEIGHBORS_3D_MAX = 26 }
 Largest neighborhoods: 8 neighbors of a pixel, 26 neighbors of a voxel.

Functions

p26_status p26_neighborhood_init (const p26_image *img, int connectivity, p26_neighborhood *neighborhood)
 Builds the neighborhood of the given connectivity for img's geometry.
int p26_neighbor (const p26_neighborhood *neighborhood, const p26_image *img, p26_index i, int k, p26_index *neighbor_index)
 Finds neighbor k of pixel i, if it lies inside the image.

Detailed Description

Neighborhoods of digital topology on the square and cubic grids.

In 2D a pixel has 4 neighbors sharing an edge with it, or 8 neighbors sharing an edge or a corner. In 3D a voxel has 6 neighbors sharing a face, 18 sharing a face or an edge, or 26 sharing a face, an edge or a corner. A p26_neighborhood lists the displacements (dx, dy, dz) of these neighbors, together with the matching index offsets for one image geometry. The order is Pink's in 2D; in 3D it is lexicographic (dz, dy, dx), which differs from Pink's voisin6/voisin18/voisin26: compare k-indexed tables with Pink only through (dx, dy, dz).

Function Documentation

◆ p26_neighborhood_init()

p26_status p26_neighborhood_init ( const p26_image * img,
int connectivity,
p26_neighborhood * neighborhood )

Builds the neighborhood of the given connectivity for img's geometry.

Neighbor order (k = 0 .. n-1), y pointing down as in Pink:

  • 2D, 8-connectivity: E, NE, N, NW, W, SW, S, SE (Pink's order); 4-connectivity keeps E, N, W, S.
  • 3D: lexicographic, dz, then dy, then dx, each from -1 to 1, skipping the center and the displacements not adjacent for the chosen connectivity. This is NOT Pink's 3D order (e.g. voisin6 uses E, N, W, S, front, back): the rank k of a 3D neighbor differs from Pink's.
Parameters
imgImage whose geometry (rs, cs) gives the offsets.
connectivity4 or 8 for a 2D image; 6, 18 or 26 for a 3D image.
neighborhoodReceives the neighborhood.
Returns
P26_OK; P26_E_INVALID_ARG if img or neighborhood is NULL, img->ndim is not 2 or 3, or connectivity does not match img->ndim. On error, neighborhood->n is 0 (an empty neighborhood) when neighborhood is not NULL.

◆ p26_neighbor()

int p26_neighbor ( const p26_neighborhood * neighborhood,
const p26_image * img,
p26_index i,
int k,
p26_index * neighbor_index )

Finds neighbor k of pixel i, if it lies inside the image.

This is the safe, general accessor: it checks every bound. Inner loops of operators use neighborhood->offset directly after handling the border.

Only img->ndim is checked (this is called once per neighbor): img must be the image the neighborhood was built for, or one of the same geometry, otherwise the offsets do not match its rows and planes.

Parameters
neighborhoodNeighborhood built for img by p26_neighborhood_init().
imgThe image the neighborhood was built for.
iIndex of the pixel.
kRank of the neighbor, 0 .. neighborhood->n - 1.
neighbor_indexReceives the index of the neighbor when it exists.
Returns
1 if the neighbor lies inside the image (and *neighbor_index is set); 0 otherwise, including when an argument is NULL, img->ndim is not 2 or 3, k is out of range or i is not an index of img. *neighbor_index is untouched when 0 is returned.