Indexing a multidimensional matrix with a second logical matrix

2 ビュー (過去 30 日間)
Marc Laub
Marc Laub 2022 年 2 月 8 日
編集済み: Walter Roberson 2022 年 2 月 8 日
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

採用された回答

Walter Roberson
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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by