数字图像处理-图像的平滑和锐化。

来源:互联网 发布:长虹网络电视看直播 编辑:程序博客网 时间:2024/05/30 04:04

图像的平滑和锐化是两个相反的过程。
吃完饭再来写注释。。。

rice=imread('rice.png');//打开照片。BW=rice;//得到矩阵G=imnoise(BW,'gaussian');//给bw矩阵添加高斯噪声。subplot(1,3,1);/设置2*2的单元格,显示他们imshow(rice);//显示正常的subplot(1,3,2);imshow(G);//显示已经添加高斯消元的.H=averfile(G,3);//调用函数。subplot(1,3,3);imshow(H);imrite(H,'after.png');function D=averfile(x,n)a=ones(n);[M,N]=size(x);x1=double(x);x2=x1;for i=1:M-n+1    for j=1: N-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=unitS(x2);BW=imread('circles.png');Buffer=BW;subplot(1,2,1);imshow(BW);[M,N]=size(BW);for i=2:M-1    for j=2:N-1        if(BW(i,j)==255 & BW(i-1,j)==255 & BW(i+1,j)==255 & BW(i,j-1)==255 & BW(i-1,j-1)==255 & BW(i,j+1)==255 & BW(i-1,j+1)==255 & BW(i+1,j+1)==255 & BW(i+1,j-1)==255)            Buffer(i,j)=0;//图像锐化。        end    endendsubplot(1,2,2);imshow(Buffer);l=imread('rice.png');G=imnoise(l,'gaussian');subplot(2,4,1);imshow(l);[BW1,thresh1]=edge(l,'roberts');//用不同的板子得到不同的结果,[BW2,thresh2]=edge(l,'sobel');[BW3,thresh3]=edge(l,'prewitt');subplot(2,4,2);imshow(BW1);subplot(2,4,3);imshow(BW2);subplot(2,4,4);imshow(BW3);[BW4,thresh4]=edge(G,'roberts');[BW5,thresh5]=edge(G,'sobel');[BW6,thresh6]=edge(G,'prewitt');subplot(2,4,5);imshow(BW4);subplot(2,4,6);imshow(BW5);subplot(2,4,7);imshow(BW6);
0 0
原创粉丝点击