findding neares label

2 Ansichten (letzte 30 Tage)
Mohammad Golam Kibria
Mohammad Golam Kibria am 20 Jun. 2011
Hi I have the following 3 matrix. I =
0 0 1 1 0 0
0 1 0 0 1 0
1 0 0 0 0 1
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
I1 =
0 0 0 0 0 0
0 1 1 1 1 0
1 0 0 0 0 1
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
I2 =
0 0 0 0 0 0
0 0 0 0 0 0
1 0 0 0 0 1
0 1 0 0 1 0
0 0 1 1 0 0
0 0 0 0 0 0
I need to know the 1s in I1 is closer to the which matrices' 1s. Here If some one looks at the matrix then obviously 1s in I1 is closer to the 1s in I than in I2.
Is there any one to help?
Thanks

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 20 Jun. 2011
so
D = bwdist(I)
P1 = sum(D(logical(I1)))
P2 = sum(D(logical(I2)))
if P1 < P2 , disp('I1 is closer to the 1s in I than in I2');
else disp('I2 is closer to the 1s in I than in I1'); end

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 20 Jun. 2011
V = 1:size(I,1);
Ipos = V * I;
I1pos = V * I1;
I2pos = V * I2;
I1score = sum(abs(Ipos-I1pos));
I2score = sum(abs(Ipos-I2pos));
if I1score < I2score
%I1
elseif I1score > I2score
%I2
else
%equal
end
This is based on my arbitrary meaning of "closer", as you are very vague as to what "closer" means.
  1 Kommentar
Mohammad Golam Kibria
Mohammad Golam Kibria am 20 Jun. 2011
for I1 and I,pixel distance having 1 are 0,0,1,1,0,0 and for I1 and I2 are 0,2,root(3),root(3),2,0, so it may be consider that s in I1 is closer to the 1s in I than in I2.
perhaps now it is clear

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by