clear all,close all;
a=imread('grab1003.bmp');
%读取图像
level=graythresh(a);
b=im2bw(a,level);
figure,imshow(b);
%将图像二值化,并将二值图像显示出来
c=b(340:402,70:411);
figure,imshow(c);
%区域划分,并将目标区域显示出来
d=double(a(338:404,67:414));
figure,imshow(d);
K1=[1 1 1 0 0 0 0;
0 1 1 1 0 0 0;
0 0 1 1 1 0 0;
0 0 0 1 1 1 0;
0 0 0 0 1 1 1]
K2=[0 0 1 1 1 0 0;
0 0 1 1 1 0 0;
0 0 1 1 1 0 0;
0 0 1 1 1 0 0;
0 0 1 1 1 0 0]
K3=[0 0 0 0 1 1 1;
0 0 0 1 1 1 0;
0 0 1 1 1 0 0;
0 1 1 1 0 0 0;
1 1 1 0 0 0 0]
K4=[0 0 0 0 0 0 0;
1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
0 0 0 0 0 0 0]
J1=K1/15;J2=K2/15;J3=K3/15;J4=K4/15;
maxpoint=[]
for i=3:65
for j=4:342
for s=1:5
for t=1:7
M1=J1(s,t)*d(i-3+s,j-4+t);
M2=J2(s,t)*d(i-3+s,j-4+t);
M3=J3(s,t)*d(i-3+s,j-4+t);
M4=J4(s,t)*d(i-3+s,j-4+t);
end
end
if (M1>M2)&&(M1>M3)&&(M1>M4)
maxpoint=[maxpoint;[i,j]];
else if (M2>M1)&&(M2>M3)&&(M2>M4)
maxpoint=[maxpoint;[i,j]];
else if (M3>M1)&&(M3>M2)&&(M3>M4)
maxpoint=[maxpoint;[i,j]];
else if (M4>M1)&&(M4>M2)&&(M4>M3)
maxpoint=[maxpoint;[i,j]];
end;
end;
end;
end;
end;
end;
figure,imshow(d);hold on;
plot(maxpoint(:,2),maxpoint(:,1),'r.');
hold off;
谁可以看下for循环那里到判断那里可以怎么样修改下