MATLAB: How to compare 2 binary images pixel by pixel

image analysisimage processingImage Processing Toolboxmatrixmatrix array

hello i need help please.
how to compare 2 binary images pixel by pixel? by using "for" in function "compare"?
it show me error (under text) and i do not know how to solve it:
??? Cell contents reference from a non-cell array object.
Error in ==> compare at 4
if BW1{a,b}==BW2{a,b}
Error in ==> com at 9
if compare(BW1,BW2)>100
i have this code:
if true
n=1;
p=2;
i=1;
max=100;
while p <= max
BW1=im2bw(o{n},0.4); % in "o" are colour pictures
BW2=im2bw(o{p},0.4);
if compare(BW1,BW2)>100
c{i}=o{p};
n=p;
p=p+1;
i=i+1;
else
p=p+1;
end
end
end
and function for compare:
if true
function [same] = compare( BW1, BW2 )
for a=1:500
for b=1:500
if BW1{a,b}==BW2{a,b}
same=same+1;
end
end
end
end
end

Best Answer

Change to
if BW1(a,b)==BW2(a,b)