Indexing a multidimensional matrix with a second logical matrix
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Marc Laub
il 8 Feb 2022
Modificato: Walter Roberson
il 8 Feb 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 Commenti
Risposta accettata
Walter Roberson
il 8 Feb 2022
Modificato: Walter Roberson
il 8 Feb 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!