《一些基于matlab的图像处理简单算法.doc》由会员分享,可在线阅读,更多相关《一些基于matlab的图像处理简单算法.doc(11页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、完成图像的灰度化处理:function W=hdbh(f)%f=imread(house.jpg);M N Z=size(f);g=im2double(f);W=zeros(M,N);for x=1:M for y=1:N W(x,y)=0.299*g(x,y,1)+0.587*g(x,y,2)+0.114*g(x,y,3); endendfigure,imshow(W),title(灰度处理后的图像)end完成图像的亮度调整的模块编写function y=high()f=imread(house.jpg);g=im2double(f);g1=g+0.3;imshow(g1)2.完成图像的平移
2、操作function y=py()f=imread(house.jpg);g=im2double(f);N=size(f)M=zeros(N(1),N(2);for x=1:N(1)-100 for y=1:N(2)-100 M(x,y)=g(x+100,y+100); endendimshow(M)完成对加噪图像的去噪操作(去噪模板任意,模板n*n大小,n值可调)function h=qz(a)f=imread(Desert.jpg); %读入图片;g=im2double(f); %进行灰度化处理;N=size(f); %求出此图片的大小;M1=zeros(N(1),N(2); %建立一个元
3、素全为0的二维矩阵;for x=1:N(1) for y=1:N(2) M1(x,y)=0.299*g(x,y,1)+0.587*g(x,y,2)+0.114*g(x,y,3); %把彩色图像的所有像素点灰度处理; end %关闭for循环;end %关闭for循环;figure,imshow(M1); %显示处理图像;M=imnoise(M1,salt & pepper,0.05);figure,imshow(M);b=zeros(N(1),N(2);for x=fix(a/2)+1:N(1)-fix(a/2) for y=fix(a/2)+1:N(2)-fix(a/2) Sum=0; fo
4、r i=-fix(a/2):fix(a/2) for j=-fix(a/2):fix(a/2) Sum=Sum+M(x+i,y+j); end end b(x,y)=Sum/(a*a); endendfigure,imshow(b);完成对图像的锐化处理(锐化模板任意,突出图像边缘,保留图像背景区域)function y=ruihua(f,x)g=im2double(f);figure;imshow(g);title(原图)M N=size(g);for i=2:M-1 for j=2:N-1 L(i,j)=g(i,j)+x*(4*g(i,j)-g(i-1,j)-g(i+1,j)-g(i,j-
5、1)-g(i,j+1); endendfigure;imshow(L);title(锐化后的图像)完成对图像放大(或缩小)n倍的操作。function A=fd(f,a,b)g=im2double(f);M,N=size(g);A=zeros(a*M,b*N);for i=1:fix(a*(M-1) for j=1:fix(b*(N-1) A(i,j)=g(ceil(i/a),ceil(j/b); endendfigure,imshow(A); title(放大后的图像)缩小处理的代码:function A=sx(f,a,b)g=im2double(f);M,N=size(g);A=zeros
6、(fix(M*a),fix(N*b);for i=2:M-1 for j=2:N-1 A(fix(a*i),fix(b*j)=g(i,j); endendfigure,imshow(A);title(缩小后的图像)完成一个对图像显示效果变换的操作(如:马赛克,浮雕效果、伪彩色效果、曝光效果等等)阳刻function M=fudiaoyang(f)m n=size(f);M=zeros(m,n);c=128/255;for i=1:m-1 for j=1:n-1 M(i,j)=f(i,j)-f(i+1,j+1)+c; endendfigure,imshow(M)阴刻function M=fudi
7、aoyin(f)g=im2double(f);m n=size(g);M=zeros(m,n);c=128/255;for i=2:m for j=2:n M(i,j)=f(i,j)-f(i-1,j-1)+c; endendfigure,imshow(M)伪彩色function M=weicaise(f)g=im2double(f);m n=size(g);M=zeros(m,n,3);for i=1:m for j=1:n if 0g(i,j)1/4 M(i,j,1)=0; M(i,j,2)=4*g(i,j); M(i,j,3)=1; else if 1/4g(i,j)1/2 M(i,j,1
8、)=0; M(i,j,2)=1; M(i,j,3)=-4*g(i,j)+2; else if 1/2g(i,j)3/4 M(i,j,1)=4*g(i,j)-2; M(i,j,2)=1; M(i,j,3)=0; else if 3/4g(i,j)=0.5;figure,imshow(L),title(二值化处理后的图像)end膨胀(3*3全一模版)function g=pengz(f)m n=size(f);g=zeros(m,n);g=im2double(g);for x=2:m-1 for y=2:n-1 if f(x,y)=1 for i=-1:1 for j=-1:1 g(x+i,y+j
9、)=1; end end end endend图像的边缘提取 完成对图像边缘提取二值化的操作。二值操作function L=erzhi(W)L=M=0.5;figure,imshow(L),title(二值化处理后的图像)end腐蚀的代码:function Y=fushi(f)m n=size(f);f=im2double(f)Y=zeros(m,n);Y=im2double(Y);for x=2:m-1 for y=2:n-1 flag=0; for i=-1:1 for j=-1:1 if f(x+i,y+j)=1 flag=flag+1; end end end if flag=9 Y(x,y)=1; end endend figure,imshow(Y)title(腐蚀后的图像)主函数:clcclearL=erzhi(f);g=fushi(L);y=L-g;figure,imshow(y);title(边缘提取后的图像)end第 11 页