实验文档
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验一:
rgb=imread('lena.bmp');
gray1=rgb2gray(rgb); % 色彩转换成灰度
a=0.5; b=150; % 可根据实际需要进行改变
gray2=a*gray1+b;
figure(1)
subplot(1,2,1),imshow(gray1,[]),title('原图'); subplot(1,2,2),imshow(gray2,[]),title('线性变换');
%imshow(rgb)
figure(2)
subplot(211)
imhist(gray1)
title('变换前的灰度直方图')
subplot(212)
imhist(gray2)
title('变换后的灰度直方图')
figure(3)
subplot(211)
histeq(gray1,3)
title('灰度均衡化的图片')
t=histeq(gray2,3)
subplot(212)
imhist(t)
title('灰度均匀化后直方图')
实验二:
clc
clear all
close all
A=imread('lena.bmp');
[height,width,dim]=size(A);
tform=maketform('affine',[-1 0 0; 0 1 0;width 0 1]); %定义水平镜像变换矩阵
B=imtransform(A,tform,'nearest');%%%'nearest':插值方式
tform2=maketform('affine',[1 0 0; 0 -1 0;0 height 1]); %定义竖直镜像变换矩阵
C=imtransform(A,tform2,'nearest');
D=imresize(A,1.5)
E=imresize(A,0.1)
F=imrotate(A,-90,'nearest','crop');
figure(1)
imshow(A),title('原图');
figure(2)
imshow(B),title('水平镜像');
figure(3)
imshow(C),title('垂直镜像');
figure(4)
imshow(D),title('放大')
figure(5)
imshow(E),title('缩小')
figure(6)
imshow(F),title('旋转')
实验三:
clc
A1=imread('lena.bmp'); %读入图像
A=rgb2gray(A1);
%平均滤波(滑动窗口)
b1=fspecial('average',3);%生成滤波算子
B1=imfilter(A,b1);
B2=medfilt2(A); %中值滤波
AA=double(A);
w1=[0 1 0; 1 -4 1; 0 1 0];
B3=imfilter(AA,w1,'corr','replicate'); %拉普拉斯锐化滤波,在滤波过程中使用相关;图像大小通过复制外边界的值来扩展,以此来处理边界充零问题
AAA=imnoise(A,'salt & pepper',0.25); %加噪声
C1=imfilter(AAA,b1);
C2=medfilt2(AAA);
C3=imfilter(double(AAA),w1,'corr','replicate') ;
figure(1)
subplot(2,5,1),imshow(A),title('原图');
subplot(2,5,2),imshow(B1),title('均值滤波'); subplot(2,5,3),imshow(B2),title('中值滤波'); subplot(2,5,4),imshow(B3,[]),title('拉普斯锐化');
subplot(2,5,5),imshow(AA-B3,[]),title('锐化后图像');
subplot(2,5,6),imshow(AAA),title('加噪声'); subplot(2,5,7),imshow(C1),title('均值滤波'); subplot(2,5,8),imshow(C2),title('中值滤波'); subplot(2,5,9),imshow(C3,[]),title('拉普斯锐化');
subplot(2,5,10),imshow(double(AAA)-C3,[]),titl e('锐化后的图像')
figure(2)
subplot(121)
BW = edge(A,'sobel')
imshow(BW)
title('sobel锐化')
subplot(122)
BW2=edge(A,'roberts')
imshow(BW2)
title('roberts锐化')
实验四:
I=imread('lena.bmp');
I=rgb2gray(I);
fftI=fft2(I);%二维离散傅立叶变换
sfftI=fftshift(fftI);%直流分量移到频谱中心
RR=real(sfftI);%取傅立叶变换的实部
II=imag(sfftI); %取傅立叶变换的虚部
A=sqrt(RR.^2+II.^2); %计算幅度谱幅值
B=(A-min(min(A)))./(max(max(A))-min(min(A)))*2 25; %归一化
C=angle(sfftI)
C1=C
figure(1)%设定窗口