VMneighborhood

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.7, Creation date: 2019-07-28, Last change: 2025-09-14

returns of a n x m or n x m x k 2D or 3D Matrix the neighborhood values

Description

This auxiliary function is used to create filter for 2D and 3D matrices
Learn also about "Structuring Elements of Matlab"

See Also:

Example Illustration

 missing image of VMneighborhood(M,nn)

Syntax

[NH,ni]=VMneighborhood([M,nn])

Input Parameter

M: Matrix, the neighborhood is desired
nn: neigborhood

Output Parameter

NH: Matrix of size [size(M) n] consisting already all neighbors
ni: Neighborhoodindex for the use like M(ni), which is the same as NH

Examples


M=nan(4,4); M(2:3,2:3)=eye(2)
M=nan(5,5,5); M(2:4,2:4,2:4)= reshape(1:27,3,3,3); M=M*10
M=nan(5,5,5); M(2:4,2:4,2:4)= reshape(floor(rand(1,27)*100),3,3,3); M=M
NH=neighborhood(M,'4'); M, NH
M=nan(4,4); M(2:3,2:3)=eye(2); NH=VMneighborhood(M,'4'); M, (sum(NH,3,'omitnan'))
M=nan(4,4); M(2:3,2:3)=eye(2); NH=VMneighborhood(M,'4'); M, (mean(NH,3,'omitnan'))
M=nan(4,4); M(2:3,2:3)=reshape(1:4,2,2)'; NH=VMneighborhood(M,'4'); M, (sum(NH,3,'omitnan'))
M=nan(4,4); M(2:3,2:3)=reshape(1:4,2,2)'; NH=VMneighborhood(M,'4'); M, (mean(NH,3,'omitnan'))
M=nan(4,4); M(2:3,2:3)=reshape(1:4,2,2)'; NH=VMneighborhood(M,'4'); M, (max(NH,'',3,'omitnan'))
M=nan(4,4); M(2:3,2:3)=reshape(1:4,2,2)'; NH=VMneighborhood(M,'4'); M, (min(NH,'',3,'omitnan'))
M=nan(4,4); M(2:3,2:3)=reshape(1:4,2,2)'; NH=VMneighborhood(M,'8'); M, (sum(NH,3,'omitnan'))
M=nan(4,4); M(2:3,2:3)=reshape(1:4,2,2)'; NH=VMneighborhood(M,'4'); M, (sum(NH,3,'omitnan'))
M=nan(4,4); M(2:3,2:3)=reshape(1:4,2,2)'; NH=VMneighborhood(M,'4'); M, IN=sum(isnan(NH),3)
M=nan(4,4); M(2:3,2:3)=reshape(1:4,2,2)'; NH=VMneighborhood(M,'4'); M, IN=sum(isnan(NH),3), M=(sum(NH,3,'omitnan'))./(4-IN)




Copyright 2019-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Last html export of this page out of FM database by TL: 2025-09-21