数字图像处理实验报告二.docx
《数字图像处理实验报告二.docx》由会员分享,可在线阅读,更多相关《数字图像处理实验报告二.docx(11页珍藏版)》请在冰点文库上搜索。
数字图像处理实验报告二
实验报告
课程名称数字图像处理
实验项目实验2MATLAB图像的空间变换及相邻区域和块的处理
实验仪器WindowsXP、MATLAB7.9.0(R2009b)
系别__信息与通信工程系____
专业____电子信息工程______
班级/学号_电信0904/20090106**__
学生姓名__whx________
实验日期_2012年5月23日___
成绩_______________________
指导教师______王勇__________
实验2MATLAB图像的空间变换及相邻区域和块的处理
一、实验目的
1.掌握MATLAB的基本应用方法。
2.掌握MATLAB空间变换--图像插值、缩放、旋转、剪切。
3.掌握MATLAB相邻区和块的处理-滑动窗和图像块操作。
二、实验的硬件、软件平台
1.硬件:
计算机
2.软件:
操作系统:
WindowsXP
3.应用软件:
MATLAB7.9.0(R2009b)
三、实验实现的MATLAB图像处理代码及其功能注释
1.了解图像插值的方法和应用。
MATLAB帮助位置:
ImageProcessingToolbox-UserGuide-SpatialTransformations-Interpolation
2.了解图像相邻区域和块的处理-滑动窗和图像块操作。
MATLAB帮助位置:
ImageProcessingToolbox–UserGuide-NeighborhoodandBlockOperation
3.放大和缩小一幅图像(imresize)。
MATLAB帮助位置:
ImageProcessingToolbox-UserGuide-SpatialTransformations-ImageResizing
4.旋转一幅图像(imrotate)。
MATLAB帮助位置:
ImageProcessingToolbox-UserGuide-SpatialTransformations-ImageRotation
5.滑动邻域操作(nlfilter)。
MATLAB帮助位置:
ImageProcessingToolbox-UserGuide-–NeighborhoodandBlockOperation–SlidingNeighborhoodOperations-LinearandNonlinearFiltering
6.图像块操作(blockproc)。
●MATLAB帮助位置1:
ImageProcessingToolbox-UserGuide-NeighborhoodandBlockOperation–DistinctBlockOperations
●MATLAB帮助位置2:
ImageProcessingToolbox-UserGuide-Transforms–DiscreteCosineTransform-TheDCTandImageCompression(使用8-by-8blocksDCT变换对图像进行压缩与解压缩,利用函数dctmtx,blockproc)更改mask矩阵的值观察解压缩重构图像的变化。
图像处理实验2代码及
清屏函数1
读取数据1
图像插值1
滑动窗和图像块操作4
放大和缩小5
图像旋转6
图像滑动邻域操作7
矩阵块操作8
DCT变换(mark=2)9
DCT(mark=4)10
DCT(mark=6)10
DCT(mark=8)10
mm11
清屏函数
clc;clear;closeall;
读取数据
loadMyImage_2
e=rgb2gray(MyImage);
图像插值
figure('Name','原图','MenuBar','none')
imshow(MyImage);
figure('Name','最近邻插值算法','MenuBar','none')
a1=imresize(MyImage,[500563],'nearest');
imshow(a1);
figure('Name','双线性插值算法','MenuBar','none')
a2=imresize(MyImage,[500563],'bilinear');
imshow(a2);
figure('Name','双三次插值算法','MenuBar','none')
a3=imresize(MyImage,[500563],'bicubic');
imshow(a3);
滑动窗和图像块操作
figure('Name','把图像分成30*30,分别缩小50%','MenuBar','none')
fun=@(x)imresize(x.data,0.5);
b1=blockproc(MyImage,[3030],fun);
imshow(b1);
放大和缩小
figure('Name','把图像放大150%','MenuBar','none')
c1=imresize(MyImage,1.5);
imshow(c1);
figure('Name','把图像缩小为50%','MenuBar','none')
c2=imresize(MyImage,0.5);
imshow(c2);
图像旋转
figure('Name','逆时针旋转30°,并采用双三次插值算法','MenuBar','none')
d1=imrotate(MyImage,30,'bicubic');
imshow(d1);
图像滑动邻域操作
figure('Name','每个3*3邻域进行标准方差的运算','MenuBar','none')
e1=nlfilter(e,[3,3],'std2');
imshow(e1);
矩阵块操作
figure('Name','每一块的内容变成每一块当中标准差的数值','MenuBar','none')
fun2=@(x)uint8(mean2(x.data)*ones(size(x.data)));
f=blockproc(e,[88],fun2);
imshow(f,[]);
DCT变换(mark=2)
I=imread('cameraman.tif');
I=rgb2gray(uint8(MyImage_2));
I=im2double(I);
T=dctmtx(8);
dct=@(block_struct)T*block_struct.data*T';
B=blockproc(I,[88],dct);
mask=mm
(2);
B2=blockproc(B,[88],@(block_struct)mask.*block_struct.data);
invdct=@(block_struct)T'*block_struct.data*T;
I2=blockproc(B2,[88],invdct);
figure,imshow(I),
figure('Name','mark=2','MenuBar','none')
imshow(I2)
Undefinedfunctionorvariable'MyImage_2'.
Errorintuxiang(line46)
I=rgb2gray(uint8(MyImage_2));
DCT(mark=4)
mask=mm(4);
B2=blockproc(B,[88],@(block_struct)mask.*block_struct.data);
invdct=@(block_struct)T'*block_struct.data*T;
I2=blockproc(B2,[88],invdct);
figure('Name','mark=4','MenuBar','none')
imshow(I2)
DCT(mark=6)
mask=mm(6);
B2=blockproc(B,[88],@(block_struct)mask.*block_struct.data);
invdct=@(block_struct)T'*block_struct.data*T;
I2=blockproc(B2,[88],invdct);
figure('Name','mark=6','MenuBar','none')
imshow(I2)
DCT(mark=8)
mask=mm(8);
B2=blockproc(B,[88],@(block_struct)mask.*block_struct.data);
invdct=@(block_struct)T'*block_struct.data*T;
I2=blockproc(B2,[88],invdct);
figure('Name','mark=8','MenuBar','none')
imshow(I2)
四、实验体会
通过本次试验基本掌握了MATLAB的基本应用方法、掌握MATLAB空间变换--图像插值、缩放、旋转、剪切、掌握MATLAB相邻区和块的处理-滑动窗和图像块操作。
受益匪浅、感触良多。