Vectorization, check if points coordinate is exist in an image or no

1 回表示 (過去 30 日間)
Mahsa
Mahsa 2017 年 10 月 9 日
コメント済み: Mahsa 2017 年 10 月 12 日
Can anyone help me to vectorize this for loop. It is basically ckecking if the x and y coordinate of is one in N matrix or not. Thank you
for i = 1:length(coordinates)
DD = coordinates(i,:);
DDD = N(DD(1),DD(2));
if DDD ==1
%%%if the dicom point is inside the mask
signVector(i) = -1;
else
%%%if the dicom point is outside the mask
signVector(i) = +1;
end
end

採用された回答

Teja Muppirala
Teja Muppirala 2017 年 10 月 10 日
signVector = ones(size(coordinates,1),1);
inds = sub2ind(size(N),coordinates(:,1),coordinates(:,2)); % Convert to linear indices
signVector( N(inds)==1 ) = -1;
  1 件のコメント
Mahsa
Mahsa 2017 年 10 月 12 日
Thank you. I was not aware of sub2ind function.

サインインしてコメントする。

その他の回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2017 年 10 月 9 日
編集済み: Andrei Bobrov 2017 年 10 月 9 日
ii = coordinates;
d3 = N(ii(:,1),ii(:,2));
signVector = -ones(numel(d3),1);
signVector(d3 ~= 1) = 1;
  2 件のコメント
Mahsa
Mahsa 2017 年 10 月 9 日
Thank you. but it did not work d3 should be a vector not a matrix
Image Analyst
Image Analyst 2017 年 10 月 10 日
Give us code, or a .mat file, to generate coordinates so we can see what you're seeing.

サインインしてコメントする。


Image Analyst
Image Analyst 2017 年 10 月 9 日
Be careful. If coordinates is an array of (x,y) and N is an array, then you'll need to check N(y, x), not N(x,y) as you have perhaps done. Remember (row, column) is (y, x) NOT (x,y).

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by