当前位置 博文首页 > 缘分锝天空的博客:计算机图像处理实验六:频域空间图像处理技术
【实验名称】
频域空间图像处理技术
?【实验目的】
1、通过本次实验掌握频域空间图像处理技术;
2、熟悉使用MATLAB库函数fft2, ifft2, fftshift, ifftshift, meshgrid, imnoise;
3、通过本次实验掌握频域距离函数的生成技术;
?【实验内容】
?【实验代码】
题1
%提示:输入参数M,N;输出D % 方法1 % 使用for循环计算距离函数 clc;clear all;close all; %图像大小 m=5; n=3; %中心点坐标 mc=floor(m/2)+1; nc=floor(n/2)+1; %循环 for i=1:m for j=1:n D(i,j)=sqrt((i-mc)^2+(j-nc)^2); end end %输出结果 D % 方法2 clc;clear all;close all; %图像大小 M=5; N=3; %中心点坐标 Mc=floor(M/2)+1; Nc=floor(N/2)+1; x=1:M; y=1:N; [X,Y]=meshgrid(y,x); Duc=sqrt((Y-Mc).^2+(X-Nc).^2); Duc
题2
%高斯噪音 理想低通滤波 Img=imread('实验6_Fig1.jpg'); figure(1) subplot(1,2,1); imshow(Img); title('原图'); Imgno=imnoise(Img,'Gaussian',0,0.01); subplot(1,2,2); imshow(Imgno); title('高斯噪音'); [M,N]=size(Img); D=DFunc(M,N); fno=fft2(Imgno); fnos=fftshift(fno); D0=[5,15,30,80,230]; for i=1:length(D0) H=D<=D0(i); I=fnos.*H; Iis=ifft2(Iis); Ireal=real(Iif); Imax=max(Ireal(:)); Imgnew=uint8(255*(Ireal/Imax)); figure(2) subplot(2,length(D0),i); imshow(Imgnew); title(['距离D0=',num2str(D0(i)),'理想低通滤波']) end
题3
clear all; %阈值 d0=50; image=imread('实验6_Fig1.jpg'); [M ,N]=size(image); %傅里叶变换得到频谱 img_f = fft2(double(image)); %移到中间 img_f=fftshift(img_f); %中心点坐标 m_mid=floor(M/2); n_mid=floor(N/2); %高斯低通滤波器构造 h = zeros(M,N); for i = 1:M for j = 1:N d = ((i-m_mid)^2+(j-n_mid)^2); h(i,j) = exp(-(d)/(2*(d0^2))); end end img_lpf = h.*img_f; %中心平移回原来状态 img_lpf=ifftshift(img_lpf); %反傅里叶变换,取实数部分 img_lpf=uint8(real(ifft2(img_lpf))); subplot(1,2,1);imshow(image);title('原图'); subplot(1,2,2);imshow(img_lpf);title('高斯低通滤波d=50');
?【运行结果】
题1
题2
题3
?
?
cs下一篇:没有了