Indexing a multidimensional matrix with a second logical matrix
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Marc Laub
le 8 Fév 2022
Modifié(e) : Walter Roberson
le 8 Fév 2022
Hello,
I want to setup dummy orientation given a binary image.
I have a binary images (data) with withe regions separated from each other with black borders.
I now want to setup the orientation data that each white pixel has the oriantation value zeros(3,3) and each black pixel has ones(3,3).
So I startet with:
ori=zeros(3,3,size(data,1),size(data,2));
ori(:,:,data==0)=ones(3,3);
but that doenst work.
So even so data==0 is a 2d logical matrix, within ori(:,:,data==0) it becomes linear and I get the error that left site is 3-by-3-by 14262 (sum of 0 elements in data) and right side only 3by3.
How can I bypass that, or is it even possible to do is by logical ndexing without looping row or columnwise??
Many thanks in advance
0 commentaires
Réponse acceptée
Walter Roberson
le 8 Fév 2022
Modifié(e) : Walter Roberson
le 8 Fév 2022
mask = data==0;
ori(:,:,mask) = ones(3,3, nnz(mask)) ;
However I would want to test this. If it works it would likely only be because the values being copied are all the same; if there was a pattern being set such as a cross, then my suspicion is that the memory locations would be out of order.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!