




已阅读5页,还剩33页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验二%图像文件读取a=imread(lyy.tif);%图像写入imwrite(a,lyy.tif);%读取照片信息sizeofa=size(a);inf=imfinfo(lyy,tif);%显示照片imshow(a)%将彩图转换为灰度图I = imread(lyy.tif);B= rgb2gray(I);figure, imshow(B), figure, imshow(I);%灰度图像转化rgb=imread(lyy.tif);x1 map1=rgb2ind(rgb,64);x=ind2gray(x1,map1);imshow(x1,map1)figure,imshow(x)%调整灰度图像对比度clear all; close all;I=imread(lyy.tif);P=rgb2gray(I);J=imadjust(P, 0.2 0.5, 0 1);figure;subplot(131);%原图imshow(uint8(I);subplot(132);%灰度图imshow(uint8(P);subplot(133);%经过灰度变换后的灰度图imshow(uint8(J);%获取图像直方图p=imread(lyy.tif);i=rgb2gray(p);imhist(i)%直方图均衡化M = imread(lyy.tif);I=rgb2gray(M);J = histeq(I);imshow(I)figure, imshow(J)均衡化前的图像均衡化后的图像%直方图规范化close all; %关闭当前所有图形窗口,清空工作空间变量,清除工作空间所有变量clear all;clc;R=imread(lyy.tif);%读入原图像,赋值给RJ=rgb2gray(R); %将彩色图像数据R转换为灰度图像数据JM,N=size(J); %获得灰度图像数据J的行列数M,Nx=1;y=1; %定义行索引变量x、列索引变量yfor x=1:M for y=1:N if (J(x,y)35&J(x,y)75); H(x,y)=(105/180)*J(x,y)-75+150; end endendset(0,defaultFigurePosition,100,100,1000,500);%修改图形图像位置的默认设置set(0,defaultFigureColor,1 1 1)%修改图形背景颜色的设置subplot(121),imshow(J)%显示处理前后的图像subplot(122),imshow(H);规定化前的图像规定化后的图像%初始操作fn=imread(cameraman.tif);%读取图像%加噪声与噪声处理%加噪声I = imread(cameraman.tif);%原图像J = imnoise(I,salt & pepper,0.02);%加噪声J1=imnoise(I,gaussian);subplot(311),imshow(I)title(原图像)subplot(312), imshow(J)title(椒盐噪声)subplot(313)imshow(J1)title(高斯噪声)%处理噪声w4=fspecial(laplacian,0);g4=fn-imfilter(J,w4,replicate);g41=fn-imfilter(J,w4,symmetric);g42=fn-imfilter(J,w4,circular);g43=fn-imfilter(J1,w4,replicate);g44=fn-imfilter(J1,w4,symmetric);g45=fn-imfilter(J1,w4,circular);%显示椒盐噪声过滤效果效果subplot(424)imshow(fn)title(原图)subplot(421),imshow(g4)%replicate办法title(replicate办法处理椒盐噪声)subplot(422),imshow(g41)%symmetric办法title(symmetric办法处理椒盐噪声)subplot(423),imshow(g42)%circular办法title(circular办法处理椒盐噪声)subplot(425)imshow(g43)title(replicate办法处理高斯噪声)subplot(426)imshow(g44)title(symmetric办法处理高斯噪声)subplot(427)imshow(g45)title(circular办法处理高斯噪声)%对椒盐噪声做10次均值滤波H1= fspecial(average,10);jiao1 = imfilter(J,H1,replicate);subplot(211)imshow(J)title(加噪声图像)subplot(212)imshow(jiao1);title(10次均值滤波)%对椒盐噪声做20次均值滤波H2 = fspecial(average,20);jiao2 = imfilter(J,H2,replicate);imshow(J)title(加噪声图像)subplot(212)imshow(jiao2);title(20次均值滤波)%用中值滤波和均值滤波处理椒盐噪声I = imread(cameraman.tif);J = imnoise(I,salt & pepper,0.02);K = medfilt2(J);%中值滤波器H2 = fspecial(average,10);jiao3 = imfilter(I,H2,replicate);subplot(311)imshow(J),title(原图像 梁逸云)subplot(312),imshow(K)title(中值滤波)subplot(313)imshow(jiao3)title(均值滤波)%低通(平滑)滤波器(利用低通领域模板进行平滑)fn=imread(cameraman.tif);k=fspecial(average);kn=filter2(k,fn)/256;%3*3平滑滤波k1=fspecial(average,9);kn1=filter2(k1,fn)/255;%9*9平滑滤波%显示subplot(3,1,1);imshow(fn)title(原图 梁逸云)subplot(3,1,2);imshow(kn)title(3*3平滑滤波)subplot(3,1,3);imshow(kn1)title(9*9平滑滤波)实验三%锐化空间滤波%线性平滑滤波器(用3*3模板处理图像)w8=1 1 1;1 -8 1;1 1 1;%创建3*3矩阵g8=fn-imfilter(fn,w8,replicate);%3*3模板,边沿处理g82=fn-imfilter(fn,w8,symmetric);%5*5模板g25=genlaplacian(fn);%显示图像(3*3模板)subplot(3,1,1);imshow(fn)title(原图 梁逸云)subplot(3,1,2);imshow(g8)title(3*3处理后的图像 梁逸云)subplot(3,1,3);imshow(g82)title(3*3模板边沿处理的图像 梁逸云)%显示图像(5*5模板)subplot(211)imshow(fn)title(原图 梁逸云)subplot(212),imshow(g25)title(5*5处理后的图像 梁逸云)%锐化增强%产生5*5,9*9,15*15,25*25大小的拉普拉斯算子w55=ones(5);w55(3,3)=w55(3,3)-25;w99=ones(9);w99(5,5)=w99(5,5)-81;w15=ones(15);w15(8,8)=w15(8,8)-152;w25=ones(25);w25(13,13)=w25(13,13)-252;%利用算子g55=fn-imfilter(fn,w55,replicate);g99=fn-imfilter(fn,w99,replicate);g15=fn-imfilter(fn,w15,replicate);g25=fn-imfilter(fn,w25,replicate);%显示效果subplot(321),imshow(fn)title(原图像 梁逸云)subplot(322),imshow(g55)title(5*5模板 梁逸云)subplot(323),imshow(g99)title(9*9模板)subplot(324),imshow(g15)title(15*15模板 梁逸云)subplot(325),imshow(g25)title(25*25模板 梁逸云)%自行设计锐化滤波器进行锐化滤波I=imread(cameraman.tif);domain=8 8 0 8 8;8 8 0 8 8;0 0 0 0 0;8 8 0 8 8;8 8 0 8 8;K1=ordfilt2(I,5,domain);%显示原图与锐化滤波器效果,进行对比subplot(211)imshow(I)title(原图 梁逸云)subplot(212)imshow(K1)title(滤波后图像)附代码中使用的genlaplacian函数function g = genlaplacian(n)%UNTITLED3 此处显示有关此函数的摘要% 此处显示详细说明w25=1 1 1 1 1;1 1 1 1 1;1 1 -24 1 1;1 1 1 1 1;1 1 1 1 1;g=n-imfilter(n,w25,replicate);end实验四%读取原图像I=imread(camen.gif);J=imread(rice.gif);subplot(427)imshow(I)%显示图像title(camen.gif)subplot(428)imshow(J)%显示图像title(rice.gif)%对原图像加高斯噪声并显示subplot(421);I=imnoise(I,gaussian);imshow(I)title(加高斯噪声的camen.gif)subplot(422);J=imnoise(J,gaussian);imshow(J)title(加高斯噪声的rice.gif)title(加高斯噪声的rice.gif)%计算频谱幅值a=ffi(I);%用函数ffi做归一化具体函数文件见附函数文件ffia1=ffi(J);%用函数ffi做归一化具体函数文件见附函数文件ffi%subplot(423)imshow(a)%显示原图像频谱title(加高斯噪声的camen.gif频谱)subplot(424)imshow(a1)title(加高斯噪声的rice.gif频谱)%高斯滤波a=ffi(I);%用函数ffi做归一化具体函数文件见附函数文件ffia1=ffi(J);%用函数ffi做归一化具体函数文件见附函数文件ffinn=fspecial(gaussian,15,40);fe=imfilter(I,nn,replicate);fe1=imfilter(J,nn,replicate);subplot(425);imshow(fe)title(高斯滤波后camen.gif)subplot(426);imshow(fe1)title(高斯滤波后rice.gif)%高斯平滑滤波n1=3;sigma1=1.5;n2=3;sigma2=1.5;theta=0;I,map=imread(camen.gif);I=imnoise(I,gaussian);a=ffi(I);%用函数ffi做归一化具体函数文件见附函数文件ffir=cos(theta) -sin(theta); sin(theta) cos(theta);for i = 1 : n2 for j = 1 : n1 u = r*j-(n1+1)/2 i-(n2+1)/2;h(i,j)=exp(-u(1)2/(2*sigma12)/(sigma1*sqrt(2*pi)*exp(-u(2)2/(2*sigma22)/(sigma2*sqrt(2*pi); endendh = h / sqrt(sum(sum(h.*h);f1=convn(I,h,same);f2=convn(a,h,same);subplot(2,2,1); imagesc(I);title(camen.gif);colormap(gray);subplot(2,2,2);imagesc(f1);title(高斯平滑滤波后的camen1.gif(3x3);colormap(gray);subplot(2,2,3); imshow(a);title(camen.gif的频谱);colormap(gray);subplot(2,2,4);imshow(f2);title(高斯滤波平滑后的camen.gif(3x3)的频谱);colormap(gray);%高斯高通滤波I=imread(camen.gif);I=imnoise(I,gaussian);a=ffi(I);%用函数ffi做归一化具体函数文件见附函数文件ffiN,M=size(I);figure;subplot(2,2,1);imshow(I)title(源图像camen.gif );subplot(222);imshow(a)title(源图像camen.gif 频谱);n1=3;sigma1=0.5;n2=3;sigma2=0.5;theta=0;r=cos(theta) -sin(theta); sin(theta) cos(theta);for i = 1 : n2 for j = 1 : n1 u = r*j-(n1+1)/2 i-(n2+1)/2;h(i,j)=exp(-u(1)2/(2*sigma12)/(sigma1*sqrt(2*pi)*exp(-u(2)2/(2*sigma22)/(sigma2*sqrt(2*pi); endendh = h / sqrt(sum(sum(h.*h);f1=convn(I,h,same);f2=convn(a,h,same);t=ones(N,M);t=f1;for i=2:N-1 for j=2:M-1 f1(i,j)=t(i+1,j)+t(i-1,j)+t(i,j+1)+t(i,j-1)-4*t(i,j); endendt1=ones(N,M);t1=f2;for i=2:N-1 for j=2:M-1 f2(i,j)=t1(i+1,j)+t1(i-1,j)+t1(i,j+1)+t1(i,j-1)-4*t1(i,j); endendsubplot(2,2,3);imshow(f1);title(高斯高通滤波后-camen.gif );subplot(2,2,4);imshow(f2)title( 高斯高通滤波后-camen.gif的频谱 );%巴特沃斯低通滤波I=imread(camen.gif);I=imnoise(I,gaussian);figure;subplot(221);imshow(I);title(灰度图像);f=double(I);g=fft2(f);g=fftshift(g);F2=log(abs(g);subplot(222);imshow(F2,InitialMagnification,fit);title(灰度图像频谱图);colormap(jet);%colorbarresult F3 =bartworL( g );%用bartworL做滤波处理,具体函数见附函数bartworLsubplot(224);imshow(F3,InitialMagnification,fit);title(巴特沃斯低通滤波后的灰度图像频谱);colormap(jet);%colorbarresult=ifftshift(result);X2=ifft2(result);X3=uint8(real(X2);subplot(223);imshow(X3);title(巴特沃斯滤波后的灰度图像);%巴特沃斯高通滤波I=imread(camen.gif);I=imnoise(I,gaussian);subplot(221);imshow(I);title(灰度图像);f=double(I);g=fft2(f);g=fftshift(g);F2=log(abs(g);subplot(222);imshow(F2,InitialMagnification,fit);title(图像的频谱图);colormap(jet);%colorbarresult F3=bartworH(g);%用bartworH做滤波处理,具体函数见附函数bartworHsubplot(224);imshow(F3,InitialMagnification,fit);title(巴特沃斯滤波后的频谱图);colormap(jet);%colorbarresult=ifftshift(result);X2=ifft2(result);X3=uint8(real(X2);subplot(223);imshow(X3);title(巴特沃斯高通滤波后的图像);%理想低通滤波器I=imread(camen.gif);J=imnoise(I,gaussian,0,0.02);subplot(1,2,1);imshow(J);title(原图);f=double(J);g=fft2(f);g=fftshift(g);M,N=size(g);d0=100;m=fix(M/2);n=fix(N/2);for i=1:Mfor j=1:Nd=sqrt(i-m)2+(j-n)2);if (d=d0) h=1; else h=0;endresult(i,j)=h*g(i,j);endendr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 校车人员安全知识培训课件
- 校安头条安全知识培训课件
- 北戴河区法律知识培训课件
- 西部计划试题及答案
- 法警聘用制面试题及答案
- java语言赋值运算符面试题及答案
- 骨科医学面试题及答案
- 2025年黑龙江省龙东地区中考语文真题(含答案)
- 科二考试题及答案
- 重庆市人民调解员考试试题及答案
- 第2章 工业机器人的运动学基础《工业机器人》教学课件
- 多发性硬化症诊治护理
- 意识形态安全面临的挑战及对策
- 直播电商行业:直播电商供应链研究报告
- 《语文核心素养三年规划》课件
- 涉诈风险账户审查表
- 广东技工学校申报设立审批表
- 大干围码头地块概况
- 企业项目投资与融资模式
- 过锡炉(波峰焊)治具制作讲义课件
- 彩钢复合板生产项目环境影响报告表
评论
0/150
提交评论