How to compare pixel co-ordination using a for loop ?

1 次查看(过去 30 天)
Here is my MATLAB code.
for j = 1 : numberOfRegions
thisBoundary = boundaries{j};
x = thisBoundary(:, 1);
y = thisBoundary(:, 2);
for j2 = 1 : numberOfRegions2
thisBoundary2 = boundaries2{j2};
x2 = thisBoundary2(:, 1);
y2 = thisBoundary2(:, 2);
if(x2==x)
if (y2 == y)
U = x2;
V = y2;
end
end
end
end
In this code I tried to compare boundary pixel co-ordinations(x,y) of two masks which I already obtained. But when it comes to the if condition it gives following error. I want to obtain the matched pixel co-ordinations and store them separately. how can I fixed that?
_ Matrix dimensions must agree. Error in (line 130) if(x2==x)_
  3 个评论
Piyum Rangana
Piyum Rangana 2017-5-24
Yes it is not equal. How can I check whether a pixel co-ordination of first boundary in a second boundary with this code then ?
Sanket Karnik
Sanket Karnik 2017-5-26
I understand that you are getting "Matrix dimensions must agree" error when you try to compare 2 matrices. As KSSV mentioned this error message suggests that you are trying to perform matrix operations on matrices of unequal dimension. If you are comparing two matrices then it is very important that both matrices are of same size. In order to answer your next question, please post here the data you are using so that we can try to advice you by referring to that data.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2017-5-26
You have to define, what should happen in x2==x. What do you want to compare? x2==x is an elementwise comparison: Either both arrays need the same size or one is a scalar. Internally the IF-condition is converted to a scalar, as needed:
if all(reshape(x2==x, 1, [])) && ~isempty(x2==x)
This must still fail. But it demonstrates, that there is more to define than just using the == operator. Perhaps you want:
if any(ismember(x2, x))
or
if all(ismember(x2, x))
or
if any(ismember(x, x2))
or what ever. You have to explain this, before a specific solution can be suggested.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by