一些基于matlab的图像处理简单算法(共8页).doc
精选优质文档-倾情为你奉上完成图像的灰度化处理: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.完成图像的平移操作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); %建立一个元素全为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; for 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-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(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=fudiaoyin(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 0<g(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/4<g(i,j)<1/2 M(i,j,1)=0; M(i,j,2)=1; M(i,j,3)=-4*g(i,j)+2; else if 1/2<g(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/4<g(i,j)<1 M(i,j,1)=1; M(i,j,2)=-4*g(i,j)+3; M(i,j,3)=0; end end end end endendfigure,imshow(M)图像的形态学处理 完成一个对图像的形态学处理方法。二值操作function L=erzhi(W)L=M>=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)=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专心-专注-专业