机器视觉实验报告_第1页
机器视觉实验报告_第2页
机器视觉实验报告_第3页
机器视觉实验报告_第4页
机器视觉实验报告_第5页
已阅读5页,还剩10页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、-大学实 验 报 告作者所在学院: 作者所在专业: 作者所在班级: 作 者 姓 名 : 实验报告1.1.1实验内容Averaging kernel(3*3 and 5*5)1.1.2算法实现clear all;clc;I=imread('.PA1House1.jpg');n=input('请输入滤波器模板大小n');K1=avefilt(I,n);figure;subplot(1,2,1);imshow(I);title('原始图像');subplot(1,2,2);imshow(K1);title('均值滤波后图像');func

2、tion d=avefilt(x,n) a=ones(n,n); p=size(x); x1=double(x);x2=x1;for i=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); endendd=uint8(x2);1.1.3实验结果1.2.1实验内容Gaussian Kernel ( =1,2,3 ) Use (2 +1)×(2 +1) as size of Kernel (You may write a separa

3、te function to generate Gaussian Kernels for different values of .)1.2.2算法实现clear all;clc;I=imread('.PA1House1.jpg');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('高斯滤波后图像');f

4、unction d=gaussfilt(k,n,s) Img = double(s); n1=floor(n+1)/2);%计算图象中心 for i=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);1.2.3实验结果1.3.1实验内容Sobel Edge Operators and Prewitt Edge Operators1.3.2算法实现clcclear allI=imread('.PA1House

5、1.jpg');J=imread('.PA1House2.jpg');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('

6、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

7、('sobel算子垂直方向边缘检测');subplot(2,2,3);imshow(K7);title('prewitt算子水平方向边缘检测');subplot(2,2,4);imshow(K8);title('prewitt算子垂直方向边缘检测');sobel算子水平方向函数function d=sobleedge(I) I1=double(I);m,n=size(I1);u=zeros(1,9);for i=2:m-1 for j=2:n-1 u(1)=-1*I(i-1,j-1);u(2)=-2*I(i-1,j);u(3)=-1*I(i-1,

8、j+1); u(4)=0*I(i,j-1);u(5)=0*I(i,j);u(6)=0*I(i,j+1); u(7)=1*I(i+1,j-1);u(8)=2*I(i+1,j);u(9)=1*I(i+1,j+1); image1(i,j)=abs(sum(u); endendd=uint8(image1);sobel算子垂直方向函数function d=sobleedgev(I) I1=double(I);m,n=size(I1);k=zeros(1,9);for i=2:m-1 for j=2:n-1 k(1)=-1*I(i-1,j-1);k(2)=0*I(i-1,j);k(3)=1*I(i-1

9、,j+1); k(4)=-2*I(i,j-1);k(5)=0*I(i,j);k(6)=2*I(i,j+1); k(7)=-1*I(i+1,j-1);k(8)=0*I(i+1,j);k(9)=1*I(i+1,j+1); image(i,j)=abs(sum(k); endendd=uint8(image);prewitt算子水平方向函数function d=Prewittedge(I) I1=double(I);m,n=size(I1);u=zeros(1,9);for i=2:m-1 for j=2:n-1 u(1)=1*I(i-1,j-1);u(2)=1*I(i-1,j);u(3)=1*I(

10、i-1,j+1); u(4)=0*I(i,j-1);u(5)=0*I(i,j);u(6)=0*I(i,j+1); u(7)=-1*I(i+1,j-1);u(8)=-1*I(i+1,j);u(9)=-1*I(i+1,j+1); image(i,j)=abs(sum(u); endendd=uint8(image);prewitt算子垂直方向函数function d=Prewittedgev(I) I1=double(I);m,n=size(I1);u=zeros(1,9);for i=2:m-1 for j=2:n-1 u(1)=-1*I(i-1,j-1);u(2)=0*I(i-1,j);u(3

11、)=1*I(i-1,j+1); u(4)=-1*I(i,j-1);u(5)=0*I(i,j);u(6)=1*I(i,j+1); u(7)=-1*I(i+1,j-1);u(8)=0*I(i+1,j);u(9)=1*I(i+1,j+1); image(i,j)=abs(sum(u); endendd=uint8(image);1.3.3实验结果2.1实验内容Attached Noisy image1 and Noisy image2 are corrupted by salt and paper noise. Apply 5by 5 Averaging and Median filter and

12、show your outputs. Why Median filter works better thanaveraging filter?2.2算法实现clear all;clc;I=imread('.PA1Noisyimage1.jpg');figure;subplot(1,3,1);imshow(I);title('噪声图像');K1=imfilter(I,fspecial('average',5);subplot(1,3,2);imshow(K1);title('5*5的均值滤波');K2=medfilt2(I,5 5)

13、;subplot(1,3,3);imshow(K2);title('5*5的中值滤波');I=imread('.PA1Noisyimage2.jpg');figure;subplot(1,3,1);imshow(I);title('噪声图像');K3=imfilter(I,fspecial('average',5);subplot(1,3,2);imshow(K3);title('5*5的均值滤波');K4=medfilt2(I,5 5);subplot(1,3,3);imshow(K4);title('5

14、*5的中值滤波');2.3实验结果均值滤波:是把每个像素都用周围的8个像素来做均值操作,幅值近似相等且随机分布在不同位置上,这样可以平滑图像,速度较快,算法简单。 但是无法去掉噪声,只能微弱的减弱它。中值滤波:常用的非线性滤波方法也是图像处理技术中最常用的预处理技术。它在平滑脉冲噪声方面非常有效,同时它可以保护图像尖锐的边缘,选择适当的点来替代污染点的值,所以处理效果好。其中加权中值滤波能够改进中值滤波的边缘信号,使其良好保持效果。3.1实验内容Compute gradient magnitude for attached image Q3_Imagei. Stretch the re

15、sulting magnitude (between 0 to 255) for better visualizationii. Compute the histogram of gradient magnitudeiii. Compute gradient orientation ( the angle of gradient vector)iv. Compute histogram of gradient orientation (angle between 0 and 2*pi)3.2算法实现clear all;clc;I=imread('.PA1Q_3.jpg');Gx

16、, Gy = gradient(I);G=sqrt(Gx.*Gx+Gy.*Gy);G1 =(G-min(min(G)./(max(max(G)-min(min(G)*255;theta=atan2(Gy,Gx);%求图像梯度方向角,其中theta的范围是-pipithta = theta;n = find(thta<0);%找出htat中小于零的值thta(n)=thta(n)+2*pi;%将thta的范围变为02*pitheta1 = thta;theta1 = rad2deg(theta1);%将theta1由弧度转换为角度theta1 = theta1(:);figure;subp

17、lot(2,2,1);imshow(I);title('原始图像');subplot(2,2,2);imshow(G1,);title('归一化梯度幅度图像');subplot(2,2,3),imshow(I);title('原始图像');subplot(2,2,4);imshow(theta);title('梯度方向图');figure,imhist(uint8(G1);title('梯度幅度直方图');figure,hist(theta1,12);%统计梯度方向直方图set(gca,'XTick'

18、;,0:30:360);%X轴的数据显示范围title('梯度方向直方图');3.3实验结果4.1实验内容Load walk_1.jpg and walk_2.jpg images in Matlab. Convert them to gray scale and subtractwalk_2.jpg from walk_1.jpg. What is the result? Why?4.2算法实现clear all;clc;I=imread('.PA1walk_1.jpg');J=imread('.PA1walk_2.jpg');figure;subplot(1,3,1);imshow(I);subplot(1,3,2);imshow(J);K=imsubtract(I,J);subplot(1,3,3);imshow(K);4.3实验结果图像减法是一种用于检测图像变化的处理方法;可以使用图像减法来检测图像相同场景图像的差异。所以相

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论