%-------------------------------------------------------------------------
clear all
x=imread('C:\wuzun.jpg'); %读取原始图像
figure(1);subplot(1,4,1);imshow(x);title('原图像1');
y=rgb2gray(x);
subplot(1,4,2);imshow(y);title('图像1的灰度图'); % 图1灰度图
u1=imnoise(y,'salt & pepper',0.07);
subplot(1,4,3);imshow(u1);title('图像1加噪声图'); %给图1加椒盐噪声
zz=medfilt2(u1,[3 3]);z=medfilt2(zz,[5 5]);%(2次中值滤波)
subplot(1,4,4);imshow(z);title('图像1中值滤波'); %图1中值滤波(3*3窗口)
% figure(6);subplot(1,2,1);imshow(zz);title('一次滤波');
% subplot(1,2,2);imshow(z);title('二次滤波');
x1=imread('C:\wuzun1.jpg');
figure(2);subplot(1,4,1);imshow(x1);title('原图像2');
y1=rgb2gray(x1);
subplot(1,4,2);imshow(y1);title('图像2灰度图'); %图2灰度图
u2=imnoise(y1,'salt & pepper',0.13);
subplot(1,4,3);imshow(u2);title('图像2叫噪声图'); %图2加椒盐噪声
zz1=medfilt2(u2,[3 3]);z1=medfilt2(zz1,[5 5]);%(2次中值滤波)
subplot(1,4,4);imshow(z1);title('图像2滤波图'); %图2中值滤波
% figure(5);subplot(1,2,1);imshow(zz1),title('一次滤波');
% subplot(1,2,2);imshow(z1);title('二次滤波');
% figure(3);subplot(1,2,1);imshow(z);title('处理后图1');
% figure(3);subplot(1,2,2);imshow(z1);title('处理后图2');
f=imsubtract(z1,z); %图1图2差分
figure(4);subplot(1,1,1);imshow(f);title('差分后图像');
% agin=medfilt2(f,[3 3]);figure(10);imshow(agin);f=agin; %差分图中值滤波
%-------------------------------------------------------------------------
%-------------------------------------------------------------------------
%眼睛的粗定位
%标注一只眼睛
[h w]=size(f);
Amax=0;m=0;n=0;
for i=10:h
for j=10:w
if Amax<=f(i,j)
Amax=f(i,j);m=i;n=j;
end
end
end
%标另外一只眼睛
Bmax=0;m1=0;n1=0;
for i1=10:m-10
for j1=10:w-10
if Bmax<=f(i1,j1)
Bmax=f(i1,j1);m1=i1;n1=j1;
end
end
end
for i2=m+10:h-10
for j2=10:w-10
if Bmax<=f(i2,j2)
Bmax=f(i2,j2);m1=i2;n1=j2;
end
end
end