图像数字处理部分程序.docx
- 文档编号:24568129
- 上传时间:2023-05-28
- 格式:DOCX
- 页数:13
- 大小:16.46KB
图像数字处理部分程序.docx
《图像数字处理部分程序.docx》由会员分享,可在线阅读,更多相关《图像数字处理部分程序.docx(13页珍藏版)》请在冰豆网上搜索。
图像数字处理部分程序
例3.1
-----------------------------------------------------------------
I=imread('');
%模拟高斯噪声
J=imnoise(I,'gaussian',0,0.02);
将多个图画到一个平面上
subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(J);
K=zeros(242,308);
fori=1:
100
J=imnoise(I,'gaussian',0,0.02);
J1=im2double(J);
K=K+J1;
end
K=K/100;
figure;
imshow(K);
-----------------------------------------------------------------
例3.2
I=imread();
J=imread();
K=imsubtract(I,J);%实现两幅图片相减
K1=255-K;
figure;imshow(I);
title('有噪声的图');
figure;imshow(J);
title('原图');
figure;imshow(K1);
title('提取的噪声');
-----------------------------------------------------------------
例3.3
I=imread();%读取一张图片
J=immultiply(I,1.2);%将此图片乘以1.2
K=immultiply(I,2);%将此图片乘以2
subplot(1,3,1),imshow(I);
subplot(1,3,2),imshow(J);
subplot(1,3,3),imshow(K);
-----------------------------------------------------------------
例3.4
moon=imread('');
I=double(moon);
J=I*0.43+90;
K=I*0.1+90;
L=I*0.01+90;
moon2=uint8(J);
moon3=uint8(K);
moon4=uint8(L);
J=imdivide(moon,moon2);
K=imdivide(moon,moon3);
L=imdivide(moon,moon4);
subplot(2,2,1),imshow(moon);
subplot(2,2,2),inshow(J,[]);
subplot(2,2,3),imshow(K,[]);
subplot(2,2,4),imshow(L,[]);
-----------------------------------------------------------------
例3.5
A=zeros(128);
A(40:
67,60:
100)=1;
figure
(1);
imshow(A);
B=zeros(128);
B(50:
80,40:
70)=1;
figure
(2);
imshow(B);
C=and(A,B);
figure(3);
imshow(C);
D=or(A,B);
figure(4);
imshow(D);
E=not(A);
figure(5);
imshow(E);
-----------------------------------------------------------------
例3.6
I=imread('');
J=imrotate(i,60,'bilinear');
K=imroatte(i,60,'bilinear','crop');
subplot(1,3,1),imshow(I);
subplot(1,3,2),imshow(J);
subplot(1,3,3),imshow(K);
-----------------------------------------------------------------
例3.7
I=imread('');
J1=imresize(I,10,'nearest');
J2=imresize(I,10,'bilinear');
J3=imresize(I,10,'bicubic');
figure
imshow(I);
title('原图');
figure
imshow(J1);
title('最近邻法');
figure
imshow(J2);
title('双线性插值法');
figure
imshow(J3);
title('三次内插法');
-----------------------------------------------------------------
P54例4.2
-----------------------------------------------------------------
%读入图像
I=imread('');
imshow(I)
%求离散傅里叶频谱
J=fftshift(fft2(I));
%对原始图像进行二维傅里叶变换,并将其坐标原点移到频谱图中央位置
figure
(2)
imshow(log(abs(J)),[8,10])
p58例4.4
I=zeros(256,256);
I(28:
228,108:
148)=1
imshow(I)
%求原始图像的傅里叶频谱
J=fft2(I);
F=abs(J);
J1=fftshift(F);
figure
imshow(J1,[550])
%构造原始图像
I=zero(256,256)
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,[550]);
P59例4.4.6
clc;
clear;
I=zeros(256,256);
I(8:
248,110:
136)=5
figure
(1)
imshow(I)
a=0.1;
%原始图像的傅里叶频谱
J3=fft2(I);
F2=abs(J3);
J4=fftshift(F2);
figure
(2)
imshow(J4,[530])
%乘以比例尺度
fori=1:
256
forj=1:
256
I(i,j)=I(i,j)*a;
end
end
%比例尺度展宽后的傅里叶频谱
J2=fft2(I);
F1=abs(J2);
J3=fftshift(F1);
figure(3)
imshow(J3,[530]);
p62例4.7
I=imread('');
figure
(1);
imshow(I);
P=I*exp(-1);
figure
(2);
imshow(P)
P1=fftshift(fft2(P));
figure(3);
imshow(log(abs(P1)),[8,10])
p63例4.8
I=imread('');
I=imnoise(I,'gaussian',0,0.01);
figiure;
imshow(I);
P=fftshift(fft2(I));
figure;
imshow(log(abs(P)),[8,10])
p64例4.9
I=imread('');
figure
(1)
imshow(real(I));
I=I(:
:
3);
fftI=fft2(I);
sfftI=fftshift(fftI);
RRfdp1=real(sfftI);
IIfdp1=imag(sfftI);
a=sqrt(RRfdp1.^2+IIfdp1.^2);
a=(a-min(min(a)))/(max(max(a))-min(min(a)))*225;
figure
(2)
imshow(real(a));
b=angle(fftI);
figure(3)
imshow(real(b));
theta=30;
RR1=a*cos(theta);
II1=a*sin(theta);
fftI1=RR1+i.*II1;
C=ifft2(fftI1)*255;
figure(4);
imshow(real(C));
MM=150;
RR2=MM*cos(angle(fftI));
II2=MM*sin(angle(fftI));
fftI2=RR2+i.*II2;
D=ifft2(fftI2);
figure(5);
imshow(real(D));
P67例4.10
%装入图像
RGB=imread('');
I=rgb2gray(RGB);
%画出图像
imshow(I);
figure
(2);
%进行余弦变换
J=dct2(I);
imshow(log(abs(J),[]);
figure(3);
J(abs(J)<10)=0;
%进行余弦反变换
K=idct2(J)/255;
imshow(K);
p67例4.11
RGB=imread('');
I=rgb2gray(RGB);
I=im2double(I);
T=dctmtx(8);
B=blkproc(I,[88],'P1*x*P2',T,T');
mask=[11110000
11100000
11000000
10000000
00000000
00000000
00000000
00000000];
B2=blkproc(B,[88],'P1.*x',mask);
I2=blkproc(B2,[88],'P1.*xP2',T',T);
figure,imshow(I);
figure,imshow(B2);
figure,imshow(I2);
例5.1Img1=imread()
figure,imshow(img1);title('originalimage');
img2=imcomplement(img1);
figure,imshow(img2);title('negativeimg2');
例5.3
I=imread('Lena.bmp');
I=rgb2gray(I);
K=16;
H=histeq(I,K);
figure,subplot(2,2,1),imshow(I,[])
subplot(2,2,1),imshow(I,[]),holdon
subplot(2,2,1),hist(double(I),16),subplot(2,2,4),hist(double(H))
例5.5
img=rgb2gray(imread('Image.bmp'));
figure;imshow(img);
img_noise=double(imnoise(img,'salt&pepper',0.06));
figure;imshow(img_noise,[]);
img_smoothed=imfilter(img_noise,fspecial('average',5));
figure;imshow(img_smoothed,[]);
例5.7
f=lowpassfilter([66],o.3,6);f=f/sum(f(:
));
I=imread('Image.bmp');
I1=uint8(round(filter2(f,double(I))));
其中,Butterworth低过滤波器函数为lowpassfilter.
functionf=lowpassfilter(sze,cutoff,n)
ifcutoff<0|cutoff>0.5
error('cutofffrequencymustbebetween0and0.5');
end
ifrem(n,1)~=0|n<1
error('nmustbeaninteger>1');
end
iflength(sze)==1
row=sze;cols=sze;
else
row=sze
(1);cols=sze
(2);
end
ifmod(cols,2)
xrange=[-(cols-1)/2:
(cols-1)/2]/(cols-1);
else
xrange=[-cols/2;(cols/2-1)]/cols;
end
ifmod(rows,2)
yrange=[-(row-1)/2:
(row-1)/2]/(rows-1);
else
yrange=[-row/2:
(row/2-1)]/rows;
end
[x,y]=meshgrid(xrange,yrange);
radius=sqrt(x.^2+y.^2);
f=ifftshift(1.0/(1.0+(radius./cutoff).^(2*n)));
例5.8
f=highpassfilter([77],0.3,6);
f1=zeros(7);f1(4,4)=1;
f=f1-f/sum(f(:
));
I=imread('Image.bmp');
I1=filter2(f,double(I));
figure,imshow(I,[])
figure,imshow(I1,[])
例5.9
[image_0,map]=imread('Image.bmp');
image_1=log(double(image_0)+1);
image_2=fft2(image_1);
n=3;D0=0.05*pi;rh=0.8;r1=0.5;
[row,col]=size(image_2);
fork=1:
1:
row
for1=1:
1:
col;
D1(k,l)=sqrt((k^2+1^2));
H(k,l)=r1+(rh/(1+(D0/D1(K,1))^(2*n)));
end
image_3=(image_2.*H);
image_4=ifft2(image_3);
image_5=(exp(image_4)-1);
figure
(1),imshow(image_0,map)
figure
(2),imshow(real(image_5),map)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图像 数字 处理 部分 程序