文件名称:数字图像处理实验课程序.doc
文件大小:45KB
文件格式:DOC
更新时间:2014-07-07 07:58:57
数字图像处理
图像反转
f=imread('breast.tif');
imshow(f)
f1=imadjust(f,[0 1],[1 0]);
figure,imshow(f1)
对数运算
f=imread('12.tif');
imshow(f)
F=fft2(f);
s=abs(F);
h=log(1+s);
FC=fftshift(h);
figure,imshow(FC,[])
直方图均衡化
f=imread('pollen.tif');
imshow(f)
h=imhist(f);
figure,stem(h,'.')
g=histeq(f,256);
figure,imshow(g)
figure,imhist(g)
低通滤波(课本P96)
f=imread('bld.tif');
imshow(f);
f1=fftshift(f);
g=abs(f1);
imshow(g,[]);
f=imread('bld.tif');
f=im2double(f);
imshow(f);
v=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9];
g1=imfilter(f,v);
figure,imshow(g1);
f=imread('bld.tif');
imshow(f);
f1=fftshift(f);
g=abs(f1);
imshow(g,[]);
f=imread('bld.tif');
f=im2double(f);
imshow(f);
h = fspecial('average',[9 9]);
g1=imfilter(f,h);
figure,imshow(g1)
h = fspecial('average',[15 15]);
g2=imfilter(f,h);
figure,imshow(g2)
拉普拉斯滤波(课本P102)
f=imread('moon.tif');
imshow(f);
f1=fftshift(f);
g=abs(f1);
imshow(g,[]);
f=imread('moon.tif');
f=im2double(f);
imshow(f);
h = fspecial('laplacian',0);
g1=imfilter(f,h);
figure,imshow(g1)
显示目的标定后的图像
f=imread('moon.tif');
imshow(f);
f=im2double(f);
imshow(f);
h = [0,1,0;1,-4,1;0,1,0];
g1=imfilter(f,h);
figure,imshow(g1,[])
拉普拉斯增强
f=imread('moon.tif');
imshow(f)
f=im2double(f);
imshow(f);
h = [0,-1,0;-1,5,-1;0,-1,0];
g1=imfilter(f,h);
figure,imshow(g1)
理想低通(课本P145)
f=imread('bld.tif');
imshow(f)
[M,N]=size(f);
F=fft2(f);
H=lpfilter('ideal',M,N,50);
G=H.*F;
g=real(ifft2(G));
figure,imshow(g,[])
高通
f=imread('bld.tif');
imshow(f)
[M,N]=size(f);
F=fft2(f);
H=1-lpfilter('ideal',M,N,50);
G=H.*F;
g=real(ifft2(G));
figure,imshow(g,[])
空间域转换成频域
f=imread('bld.tif');
f=im2double(f);
imshow(f);
h = [-1,-1,-1;-1,9,-1;-1,-1,-1];
H=freqz2(h,100,100);
H1=ifftshift(H);
figure,mesh(abs(H1));
a=max(max(H1));
b=min(min(H1))
将花心填充呈黄色
f=imread('rgbr.tif');
imshow(f)
[M,N]=size(f);
for i=1:1:M
for j=1:1:N
if f(i,j)>=220
fb(i,j)=0;
else if f(i,j)>=198&f(i,j)<220
fb(i,j)=50;
else if f(i,j)<=198
fb(i,j)=f(i,j);
end
end
end
end
end
fb=im2uint8(fb);
f2=cat(3,f,f,fb);
figure,imshow(fb);
figure,imshow(f2)
将月球边缘填充成黄色
(1)f=imread('moon.tif');
imshow(f)
[M,N]=size(f);
for i=1:1:M
for j=1:1:N
fb(i,j)=f(i,j);
fr(i,j)=0;
fg(i,j)=0;
end
end
f2=cat(3,fr,fg,fb);
figure,imshow(f2);
w=[0 -1 0;-1 5 -1;0 -1 0];
g=imfilter(f2,w);
figure,imshow(g)
[M,N]=size(g);
for i=1:1:M
for j=1:1:N
if g(i,j)<=100
gr(i,j)=g(i,j);
gg(i,j)=g(i,j);
gb(i,j)=g(i,j);
else if 100