Finds the valid 4 or 8/ 6,18 or 26 neighbors indices of a specific index (i.e. pixel/voxel) in a 2D/3D matrix.
Updated 10 Sep 2018

View License

This function is a correction and modification to findNeighbours function by Patrick Granton.
It gives the indices of valid neighbors to a pixel/voxel in a 2D/3D matrix.
Given the linear index of the pixel/voxel, the size of the 2D/3D matrix and the type of connectivity considered
(4 or 8 / 6,18 or 26 connectivity), the function gives the linear indices of the neighboring pixels/voxels within the matrix size.

Cite As

Ahmed Zankoor (2024). findNeighbours (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Added getting neighbors to pixels (elements) in a 2D image (matrix).


Thanks to Patrick Granton