Indexing a multidimensional matrix with a second logical matrix
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2022-2-8
编辑:Walter Roberson
2022-2-8
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!