------大学
实 验 报 告
作者所在学院:
作者所在专业:
作者所在班级:
作者姓名:
实验报告
Averaging kernel(3*3 and 5*5)
clear all;
clc;
I=imread('..\PA1\');
n=input('请输入滤波器模板大小\n');
K1=avefilt(I,n);
figure;
subplot(1,2,1);imshow(I);title('原始图像');
subplot(1,2,2);imshow(K1);title('均值滤波后图像');
function d=avefilt(x,n)
a=ones(n,n);
p=size(x);
x1=double(x);
x2=x1;
fori=1:p(1)-n+1
for j=1:p(2)-n+1
c=x1(i:i+(n-1),j:j+(n-1)).*a;
s=sum(sum(c)); x2(i+(n-1)/2,j+(n-1)/2)=s/(n*n);
end
end
d=uint8(x2);
Gaussian Kernel (σ =1,2,3 ) Use (2σ +1)×(2σ +1) as size of Kernel (You maywrite a separate function to generate Gaussian Kernels for different values of σ.)
clear all;
clc;
I=imread('..\PA1\');
sigma=input('请输入方差的大小\n');
n=2*sigma+1;
K1=gaussfilt(sigma,n,I);
figure;
subplot(1,2,1);imshow(I);title('原始图像');
subplot(1,2,2);imshow(K1);title('高斯滤波后图像');
function d=gaussfilt(k,n,s)
Img = double(s);
n1=floor((n+1)/2);%计算图象中心
fori=1:n
for j=1:n
b(i,j) =exp(-((i-n1)^2+(j-n1)^2)/(4*k))/(4*pi*k);
end
end
Img1=conv2(Img,b,'same');
d=uint8(Img1);
Sobel Edge Operators and Prewitt Edge Operators
clc
clear all
I=imread('..\PA1\');
J=imread('..\PA1\');
K1= sobeledge(I);%调用sobel水平算子函数
K2= sobeledgev(I);%调用sobel垂直算子函数
K3= Prewittedge(I);%调用prewitt水平算子函数
K4= Prewittedgev(I);%调用prewitt垂直算子函数
K5= sobeledge(J);
K6= sobeledgev(J);
K7= Prewittedge(J);
K8= Prewittedgev(J);
figure;
subplot(2,2,1);imshow(K1);title('sobel算子水平方向边缘检测');
subplot(2,2,2);imshow(K2);title('sobel算子垂直方向边缘检测');
subplot(2,2,3);imshow(K3);title('prewitt算子水平方向边缘检测');
subplot(2,2,4);imshow(K4);title('prewitt算子垂直方向边缘检测');
figure;
subplot(2,2,1);imshow(K5);title('sobel算子水平方向边缘检测');
subplot(2,2,2);imshow(K6);title('sobel算子垂直方向边缘检测');
subplot(2,2,3);imshow(K7);title('p
机器视觉实验报告 来自淘豆网m.daumloan.com转载请标明出处.