Effacer les filtres
Effacer les filtres

Neighbor and center points of matrix

6 vues (au cours des 30 derniers jours)
Ghulam Murtaza
Ghulam Murtaza le 30 Déc 2020
Commenté : Ghulam Murtaza le 30 Déc 2020
Hi, I have matirx of 256 \times 256. I want to find and save indices of nine neighbors of each center point in 1D matrix or in 256\times 256 matrix.
  2 commentaires
Jan
Jan le 30 Déc 2020
What does "each center point" mean? Can you give a small example of the wanted output?
Ghulam Murtaza
Ghulam Murtaza le 30 Déc 2020
I means that I have M=256x256 matrix and after padding it it becomes 258x258. Now select on center and its neighbors after that move to next center not sharing neighbor with previous center and so on.

Connectez-vous pour commenter.

Réponses (1)

Steve Eddins
Steve Eddins le 30 Déc 2020
See my 25-Feb-2008 blog post called "Neighbor indexing" for a general technique.
You'll need to pay careful attention to what happens with matrix elements that are on the edges of the matrix, as these elements don't have nine neighbors. I often zero-pad to simplify the code.
Also, in that blog post, you'll see this line of code:
neighbors = bsxfun(@plus, idx, neighbor_offsets)
In today's MATLAB, you can write that more simply as:
neighbors = idx + neighbor_offsets

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by