neighbor2ind

版本 1.0.0.0 (1.9 KB) 作者: Matthew Eicholtz
Get pairs of indices for neighboring elements in an array.
268.0 次下载
更新时间 2015/10/10

查看许可证

This function takes a size vector [m n] and a connectivity scalar (4 by default, or 8) and returns a p-by-2 array containing the linear indices of all pairs of neighboring elements in an m-by-n array. Note that p does not equal (m*n*conn) because border elements do not have as many neighbors as interior elements.
I created this function because I needed to transform an image into a graph, with edges in the graph for neighboring pixels only. This function allows me to quickly get the linear indices for all edges in that graph.

This function was inspired by a blog post from Steve Eddins found here:
http://blogs.mathworks.com/steve/2008/02/25/neighbor-indexing-2/

Examples:
ind = neighbor2ind([3,4]);

I = imread('cameraman.tif');
ind = neighbor2ind(size(I),8);

引用格式

Matthew Eicholtz (2024). neighbor2ind (https://www.mathworks.com/matlabcentral/fileexchange/53444-neighbor2ind), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2015a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0