您好,欢迎访问三七文档
一.图像基本操作1.读出指定目录下图像文件cameraman.tif(a),分别对原图进行加亮(灰度值+学号)、旋转((学号)度)、取反操作、缩放(XY(学号)),水平和垂直镜像.在同一窗口显示原图和操作后各幅图片,要求标注图标题。a=imread('cameraman.tif');subplot(2,4,1),imshow(a);title('原始图像')K=a+16;subplot(2,4,2),imshow(K);title('加亮后的像')b=imrotate(a,16);subplot(2,4,3),imshow(b);title('旋转后的图像')J=imcomplement(a);subplot(2,4,4),imshow(J);title('取反后图像')[height,width,dim]=size(a);tform=maketform('affine',[1,0,0;0,6,0;0,0,1]);B=imtransform(a,tform,'nearest');subplot(2,4,5),imshow(B);title('缩放后图像')tform1=maketform('affine',[-1,0,0;0,1,0;width,0,1]);C=imtransform(a,tform1,'nearest');subplot(2,4,6),imshow(C);title('水平镜像')tform3=maketform('affine',[1,0,0;0,-1,0;0,height,1]);D=imtransform(a,tform3,'nearest');subplot(2,4,8),imshow(D);title('垂直镜像')2.读出指定目录下图像文件rice.png(b),进行直方图均衡化,在同一窗口显示原图和均衡化图及对应直方图,要求标注图标题。b=imread('rice.png');a=histeq(b,256);subplot(2,2,1),imshow(b);title('原始图像')subplot(2,2,2),imshow(a);title('均衡化图')subplot(2,2,3),imhist(b);title('原始图的直方图')subplot(2,2,4),imhist(a);title('均衡化图的直方图')3、对a、b图像进行加、减代数运算,并进行显示。a=imread('cameraman.tif');subplot(2,2,1),imshow(a);title('a图')b=imread('rice.png');subplot(2,2,2),imshow(b);title('b图')I=double(a)-double(b);subplot(2,2,3),imshow(uint8(I));title('a-b')J=double(a)+double(b);subplot(2,2,4),imshow(uint8(J));title('a+b')4、对a进行线性变换(g=20f+40)、gamma变换(g=3f0.4)和对数拉伸变换g=50*(log(f+2)),并进行显示。a=imread('cameraman.tif');subplot(2,2,1),imshow(a);title('原始图像')[m,n]=size(a);vMax=max(max(a));vMin=min(min(a));K=zeros(256);fori=1:256forj=1:256f=double(a(i,j));K(i,j)=f*20+40;endendA=uint8(K);subplot(2,2,2),imshow(A);title('线性变换图像')J=imadjust(3*a,[],[],0.4);subplot(2,2,3),imshow(J);title('gamma变换图像')e=double(a);L=50*(log(e+2));H=uint8(L);subplot(2,2,4),imshow(H);title('对数拉伸变换图像')二.图像退化与复原1.给图像cktboard.tif(c)加入高斯噪声cg、椒盐噪声cs。c=imread('cktboard.tif');cg=imnoise(c,'gaussian',0,0.01);cs=imnoise(c,'salt&pepper',0.02);subplot(1,3,1),imshow(c);title('原始图像')subplot(1,3,2),imshow(cg);title('加入高斯噪声图')subplot(1,3,3),imshow(cs);title('加入椒盐噪声图')2.对加入噪声的图像分别进行平滑处理,采用4邻域、8邻域、1/5和1/15加权平均模版(尺寸3*3),显示滤波图像并进行比较比较说明。c=imread('cktboard.tif');cg=imnoise(c,'gaussian',0,0.01);cs=imnoise(c,'salt&pepper',0.02);M1=(1/4)*[0,1,0;1,0,1;0,1,0];M2=(1/8)*[1,1,1;1,0,1;1,1,1];M3=(1/5)*[0,1,0;1,1,1;0,1,0];M4=(1/15)*[1,2,1;2,3,2;1,2,1];Ig1=imfilter(cg,M1);subplot(4,2,1),imshow(Ig1);title('加入高斯噪声的图像4邻域平滑处理')Ig2=imfilter(cg,M2);subplot(4,2,2),imshow(Ig2);title('加入高斯噪声的图像8邻域平滑处理')Ig3=imfilter(cg,M3);subplot(4,2,3),imshow(Ig3);title('加入高斯噪声的图像1/5邻域平滑处理')Ig4=imfilter(cg,M4);subplot(4,2,4),imshow(Ig4);title('加入高斯噪声的图像1/15邻域平滑处理')Is1=imfilter(cs,M1);subplot(4,2,5),imshow(Is1);title('加入椒盐噪声的图像4邻域平滑处理')Is2=imfilter(cs,M2);subplot(4,2,6),imshow(Is2);title('加入椒盐噪声的图像8邻域平滑处理')Is3=imfilter(cs,M3);subplot(4,2,7),imshow(Is3);title('加入椒盐噪声的图像1/5邻域平滑处')Is4=imfilter(cs,M4);subplot(4,2,8),imshow(Is4);title('加入椒盐噪声的图像1/15邻域平滑处理')3.对cg和cs采用8邻域滤波,尺寸分别为3*3、5*5、7*7,显示相应图像并进行比较说明。c=imread('cktboard.tif');cg=imnoise(c,'gaussian',0,0.01);cs=imnoise(c,'salt&pepper',0.02);M=(1/8)*[1,1,1;1,0,1;1,1,1];G=imfilter(cg,M);S=imfilter(cg,M);K1=filter2(fspecial('average',3),G)/255;subplot(2,3,1),imshow(K1);title('对加入高斯噪声的图像3*3滤波')K2=filter2(fspecial('average',5),G)/255;subplot(2,3,2),imshow(K2);title('对加入高斯噪声的图像5*5滤波')K3=filter2(fspecial('average',7),G)/255;subplot(2,3,3),imshow(K3);title('对加入高斯噪声的图像7*7滤波')K4=filter2(fspecial('average',3),S)/255;subplot(2,3,4),imshow(K4);title('对加入椒盐噪声的图像3*3滤波')K5=filter2(fspecial('average',5),S)/255;subplot(2,3,5),imshow(K5);title('对加入椒盐噪声的图像5*5滤波')K6=filter2(fspecial('average',7),S)/255;subplot(2,3,6),imshow(K6);title('对加入椒盐噪声的图像7*7滤波')4.对cg和cs采用中值滤波器、Sobel算子和拉普拉斯进行锐化,显示相应图像并进行说明。c=imread('cktboard.tif');cg=imnoise(c,'gaussian',0,0.01);cs=imnoise(c,'salt&pepper',0.02);h1=medfilt2(cg,[3,3]);h2=medfilt2(cs,[3,3]);K1=filter2(fspecial('laplacian'),cg);K2=filter2(fspecial('laplacian'),cs);k1=filter2(fspecial('sobel'),cg);k2=filter2(fspecial('sobel'),cs);subplot(2,4,1),imshow(cg);title('加入高斯噪声的图像')subplot(2,4,2),imshow(h1);title('高斯中值滤波')subplot(2,4,3),imshow(K1);title('高斯拉普拉斯滤波')subplot(2,4,4),imshow(k1);title('高斯Sobel算子滤波')subplot(2,4,5),imshow(cs);title('加入椒盐噪声的图像')subplot(2,4,6),imshow(h2);title('椒盐中值滤波')subplot(2,4,7),imshow(K2);title('椒盐拉普拉斯滤波')subplot(2,4,8),imshow(k2);title('椒盐Sobel算子滤波')三.图像FFT变换1.首先构造一幅黑白二值图像,在128×128的黑色背景中心产生一个16×32的白色矩形方块,(zeros)f=zeros(128);f(57:72,49:80)=1;imshow(f)2.对这幅图像进行傅里叶变换分析,把零频率部分移到频谱中间(提示:fftshift、fft2命令);f=zeros(128);f(57:72,49:80)=1;subplot(1,3,1),imshow(f);title('原图')F=fft2(f,128,128);subplot(1,3,2),imshow(log(abs(F)),[-1,5]);title('256*256频谱图')F=fft2(f,128,128);F2=fftshift(F);subplot(1,3,3),imshow(log(abs(F2)),[-1,5]);title('零频部分移到中间图')3.对这幅图像中间的白色部分沿X轴方向移动30,并对移动后的图像进行傅里叶变换分析,和(1)所得结果比较;f=zeros(128);f(57:72,79:110)=1;subplot(1,2,1),imshow(f);title('X轴移动30')F=fft2(f,128,128);F2=fftshift(F);subplot(1,2,2),imshow(log(abs(F2)),[-1,5]);title('移动后的频谱图')4.对这幅图像中间的白色部分沿Y轴方向移动30,并对移动后的图像进行傅里叶变换分析,和(1)所得结果比较;f=zeros(128);f(87:102,49:80)=1;subplot(1,2,1),imshow(f);title('Y轴移动30')F=fft2(f,128,128);F2=fftshift
本文标题:MATLAB题目
链接地址:https://www.777doc.com/doc-5665031 .html