1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| clear all
close all
template=imread('fraiz.bmp');
A=imread('fruitsss.bmp');
template=rgb2gray(template);
A=rgb2gray(A);
[l,c]=size(template);
[lfruit,cfruit]=size(A);
template=double(template);
templatemean=mean(mean(template));
p=1;
z=1;
for i=1:cfruit-c
for j=1:lfruit-l
I2(:,:,z) = imcrop(A,[i j c-1 l-1]);
A1=uint8(I2(:,:,z));
g =A1;
gmean=mean(mean(g));
g=double(g);
for x=1:l
for y=1:c
corre(p)=((template(x,y)-templatemean)*(g(x,y)-gmean))/(sqrt(((template(x,y)-templatemean )^2)*(((g(x,y)-gmean )^2))));
p=p+1;
end
end
corre=mean(corre)
if corre>0.95
e=i;
f=j;
end
z=z+1;
end
end |
Partager