数字图像处理上机实验报告
- 格式:docx
- 大小:2.58 MB
- 文档页数:28
数字图像处理上机实验报告实验一:MATLAB工具箱的使用实验目的:11:了解matlab语言,熟悉并掌握matlab相关的处理语句。
2:了解matlab在图像处理中的优缺点。
3 熟悉matlab的使用技巧,能用matlab熟悉的对数字图像进行各种处理。
1 将一幅灰度图像转换成索引色图像。
I=imread('ngc4024m.tif');X=grayslice(I,16);imshow(I)figure,imshow(X,hot(16))2:对一副图像进行二值化处理。
load treesBW=im2bw(X,map,0.4);imshow(X,map)figure,imshow(BW)3:将索引色图像转化成灰度图像。
load treesI=ind2gray(X,map);imshow(X,map)figure,imshow(I)4:显示一幅图像。
load clown image(10,10,X) colormap(map)试验二图像变换实验目的:1 熟悉掌握DFT和DCT变换的matlab实现。
2 利用matlab试验DFT和DCT的变换,求出图像的频谱。
1.二维离散傅里叶变换的旋转型。
I=zeros(256,256);>> I(28:228,108:148)=1;>> imshow(I)J=fft2(I);>> F=abs(J);>> J1=fftshift(F);figure>> imshow(J1,[5 50])>> I(28:228,108:148)=1;>> J=imrotate(I,315,'bilinear','crop'); >>figure>> imshow(J)J1=fft2(J);>> F=abs(J1);>> J2=fftshift(F);figure>> imshow(J2,[5 50])2.图像的傅里叶频谱。
>> clear;I(8:248,110:136)=5;>> imshow(I)J3=fft2(I);>> F2=abs(J3);>> J4=fftshift(F2);figure>> imshow(J4,[5 30])3.二维余弦正反变换在Matlab中的实现。
RGB=imread('autumn.tif');>> I=rgb2gray(RGB);>> figure(1)>> imshow(I);figure(2);J=dct2(I);imshow(log(abs(J)),[]);colormap(jet(64));colorbar;figure(3);>> J(abs(J)<10)=0;>> K=idct2(J)/255;>> imshow(K);4.用DCT变换作图像压缩的例子。
>> I=imread('cameraman.tif');I=double(I)/255;T=dctmtx(8);B=blkproc(I,[8 8],'P1*x*P2',T,T');>> mask=[1 1 1 1 0 0 0 01 1 1 0 0 0 0 01 1 0 0 0 0 0 01 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 0];>> B2=blkproc(B,[8 8],'P1.*x',mask); >> I2=blkproc(B2,[8 8],'P1*x*P2',T',T); >> imshow(I),figure,imshow(I2)实验三图像灰度修正技术和直方图均衡化实验目的:1掌握图像灰度修正技术的原理和实现方法。
2 掌握图像直方图均衡化处理的方法。
实验四图像平滑实验目的:1掌握常见图像噪声类型。
2理解邻域平均法和中值滤波的原理特点和适用对象。
3掌握边缘检测的基本思想和常见的边缘算子的使用方法。
实验五图像锐化实验目的:1掌握图像锐化的主要原理和使用方法。
2掌握常见的边缘提取算法。
3利用matlab实现图像的边缘检测。
1.显示图像‘cameraman.tif’的直方图。
I=imread('cameraman.tif');>> subplot(1,2,1),imshow(I)>> subplot(1,2,2),imhist(I)2.显示图像‘bacteria.tif’的等灰度值图。
I=imread('bacteria.tif');>> subplot(1,2,1),>> imshow(I)>> subplot(1,2,2),>> imcontour(I)3.调整图像的对比度。
clear all>> I=imread('pout.tif');>> J=imadjust(I,[0.3 0.7],[]);>> subplot(121),imshow(I)>> subplot(122),imshow(J)figure,subplot(121),imhist(I) >> subplot(122),imhist(J)4.对图像‘tire.tif’做直方图均衡化。
I=imread('tire.tif');>> J=histeq(I);>> subplot(1,2,1),imshow(I)>> subplot(1,2,2),imshow(J)figure,subplot(1,2,1),imhist(I,64)>> subplot(1,2,2),imhist(J,64)5.对图像‘cameraman.tif’分别加入高斯噪声,和乘性噪声。
I=imread('cameraman.tif');J1=imnoise(I,'gaussian',0,0.02);>> J2=imnoise(I,'speckle',0.02);>> subplot(1,3,1),imshow(I);>> subplot(1,3,2),imshow(J1);>> subplot(1,3,3),imshow(J2);6.对图像分别进行各种滤波。
.读取原始图像。
g0=imread('eight.tif');>> figure(1)>> imshow(g0);.加入椒盐噪声。
g1=imnoise(g0,'salt & pepper',0.02); >> g1=im2double(g1);>> figure(2)>> imshow(g1);.进行高斯低通滤波。
h1=fspecial('gaussian',4,0.3);>> g2=filter2(h1,g1,'same');>> figure(3)>> imshow(g2);.进行soble滤波。
h2=fspecial('sobel');>> g3=filter2(h2,g1,'same');>> figure(4)>> imshow(g3);.进行prewitt滤波。
h3=fspecial('prewitt');>> g4=filter2(h3,g1,'same'); >> figure(5)>> imshow(g4);.进行拉普拉斯滤波。
h4=fspecial('laplacian',0.5); >> g5=filter2(h4,g1,'samne'); >> figure(6)>> imshow(g5);.进行高斯拉普拉斯滤波。
h5=fspecial('log',4,0.3); >> g6=filter2(h5,g1,'same'); >> figure(7)>> imshow(g6);.进行均值滤波。
h6=fspecial('average'); >> g7=filter2(h6,g1,'same'); >> figure(8)>> imshow(g7);.进行模糊滤波。
h7=fspecial('unsharp',0.3); >> g8=filter2(h7,g1,'same'); >> figure(9)>> imshow(g8);.进行高斯高通滤波。
h8=[0 -1 0;-1 5 -1;0 -1 0]; >> g9=filter2(h8,g1,'same'); >> figure(10)>> imshow(g9);.进行中值滤波。
h9=h1;g10=medfilt2(g1); figure(11) imshow(g10);实验五图像的复原。
实验目的:利用matlab实现对图像复原的操作。
1.创建一个仿真运动模糊的PSF来模糊所示图像,指定运动位移为31个像素,运动角度为11°。
I=imread('flowers.tif');>> I=I(10+[1:256],222+[1:256],:);>> subplot(1,2,1);imshow(I);>> LEN=31;>> THETA=11;>> PSF=fspecial('motion',LEN,THETA);>> Blurred=imfilter(I,PSF,'circular','conv');>> subplot(1,2,2);imshow(Blurred);2.对上图所示图像分别采用运动PSF和均值滤波PSF进行模糊,观察不同的PSF产生的效果。