function out = f_and ( in1, in2 ) % out = f_and ( in1, in2 ) % % performs in1 (feature and) in2 % feature and is like a normal 'and' operation only it operates on entire % features rather than individual bits. % if any bit in a feature in the first image is in the second image the % entire feature in the first image is kept. % feature and is not commutative out = double( in1 & in2 ); % class double so that i can manipulate it later. in1_label = bwlabel (in1, 4); % find all non zero points [i,j] = find(out); num = length(i); for n = 1:num % include entire obj is one point in it is kept if (out(i(n),j(n)) == 1) temp = in1_label(i(n),j(n)); out( find(in1_label == temp) ) = 2; % by making it 2 we make it so that each item is only searched % for once, rather than the (number of pixels in obj) times. end end out = out/2; clear