第9讲 频率域滤波彩色图像增强
- 格式:ppt
- 大小:968.50 KB
- 文档页数:28
实验五图像增强--空域、频域滤波课程名称:数字图像处理技术实验日期:2015-11-03 成绩:班级:姓名:学号:一、实验目的1.了解图像空域滤波、频域滤波的基本操作;2.掌握噪声模拟和图像滤波函数的使用方法3. 实现彩色图像的增强。
二、实验内容1. (基础题)制作自己的GUI用户界面,实现图像在空域中的均值滤波、中值滤波、锐化滤波;(提高题)定义自己的过滤器实现锐化滤波。
2. (基础题)在GUI中,实现图像的频域滤波:低通滤波、高通滤波。
3. (基础题)在GUI中,实现彩色图像增强:伪彩色增强、假彩色增强、真彩色增强。
三、实验代码function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)clear;figureA=imread('1.jpg');B=rgb2gray(A);h1=ones(7,7)/49;B2=imfilter(B,h1);h2=ones(9,9)/81;B3=imfilter(B,h2);subplot(2,2,1);imshow(B);title('灰度图像');subplot(2,2,3);imshow(B2);title('7*7均值滤波');subplot(2,2,4);imshow(B3);title('9*9均值滤波');% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)clear;figureA=imread('1.jpg');B=rgb2gray(A);B2=medfilt2(B,[5 5]);B3=medfilt2(B,[9 9]);subplot(2,2,1);imshow(B);title('灰度图像');subplot(2,2,3);imshow(B2);title('5*5中值滤波');subplot(2,2,4);imshow(B3);title('9*9中值滤波');% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear;figureA=imread('1.jpg');B=rgb2gray(A);h1=[1 2 1;0 0 0;-1 -2 -1];B2=imfilter(B,h1);h2=[1 0 -1;2 0 -2;1 0 -1];B3=imfilter(B,h2);subplot(2,2,1);imshow(B);title('灰度图像');subplot(2,2,3);imshow(B2);title('水平锐化');subplot(2,2,4);imshow(B3);title('竖直锐化');% --- Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear;figureA=imread('1.jpg');f=rgb2gray(A);subplot(2,2,1);imshow(f);f=im2double(f);F=fftshift(fft2(f));[M,N]=size(F);n = 30;D0 = 40;u0=floor(M/2);v0=floor(N/2);for u=1:Mfor v=1:ND=sqrt((u-u0)^2+(v-v0)^2);H=1/(1+(D/D0)^(2*n));G(u,v)=H*F(u,v);endendg=ifft2(ifftshift(G));g=im2uint8(real(g));subplot(2,2,4);imshow(g);% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear;figureA=imread('1.jpg');f=rgb2gray(A);subplot(2,2,1);imshow(f);f=im2double(f);F=fftshift(fft2(f));[M,N]=size(F);n = 30;D0 = 40;u0=floor(M/2);v0=floor(N/2);for u=1:Mfor v=1:ND=sqrt((u-u0)^2+(v-v0)^2);H=1/(1+(D0/D)^(2*n));G(u,v)=H*F(u,v);endendg=ifft2(ifftshift(G));g=im2uint8(real(g));subplot(2,2,4);imshow(g);% --- Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)% hObject handle to pushbutton6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear;figureA=imread('1.jpg');B=rgb2gray(A);subplot(1,2,1);imshow(B);title('灰度图像');Y=floor(B/64);[M,N]=size(Y);for i=1:Mfor j=1:Nswitch Y(i,j)case 0Y1(i,j,1:3)=[0 0 255];case 1Y1(i,j,1:3)=[200 0 200];case 2Y1(i,j,1:3)=[255 150 0];case 3Y1(i,j,1:3)=[255 255 0];otherwiseY1(i,j,1:3)=[255 255 255];endendendsubplot(1,2,2);imshow(Y1);% --- Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject handle to pushbutton7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear;figureA=imread('1.jpg');f=rgb2gray(A);subplot(1,2,1);imshow(f);title('灰度图像');[M,N]=size(f);L=255;f=double(f);f1=floor(f/64);R=f1;G=f1;B=f1;for i=1:Mfor j=1:Nswitch f1(i,j)case 0R(i,j)=0;G(i,j)=4*f(i,j);B(i,j)=L;case 1R(i,j)=0;G(i,j)=L;B(i,j)=-4*f(i,j)+2*L;case 2R(i,j)=4*f(i,j)-2*L;G(i,j)=L;B(i,j)=0;case 3R(i,j)=L;G(i,j)=-4*f(i,j)+4*L;B(i,j)=0;endendendg(:,:,1)=R;g(:,:,2)=G;g(:,:,3)=B;g=uint8(g);subplot(1,2,2);imshow(g);% --- Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear;figureRGB=imread('1.jpg');RGB = im2double(RGB);R = RGB(:, :, 1);G = RGB(:, :, 2);B = RGB(:, :, 3);subplot(1,2,1),imshow(RGB)title('原始图像');c=R.*1.26d=G.*1.03e=B.*1.15enhance=cat(3, c, d, e);subplot(1,2,2),imshow(enhance)title('RGB手动增强的图像')四、实验结果截图五、实验体会经过很长时间学会应用这些东西。
频率域波图像增强本⽂主要包括以下内容频率域图像增强⾼通滤波器和低通滤波器本章的典型案例分析利⽤频域滤波消除周期噪声频域滤波基础频域滤波与空域滤波的关系傅⽴叶变换可以将图像从空域变换到频域,⽽傅⽴叶反变换则可以将图像的频谱逆变换为空域图像,即⼈可以直接识别的图像。
这样⼀来,我们可以利⽤空域图像与频谱之间的对应关系,尝试将空域卷积滤波变换为频域滤波,然后再将频域滤波处理后的图像反变换回空间域,从⽽达到图像增强的⽬的。
这样做的⼀个最主要的吸引⼒在于频域滤波的直观性特点,关于这⼀点稍后将进⾏详细的阐述。
根据著名的卷积定理:两个⼆维连续函数在空间域中的卷积可由其相应的两个傅⽴叶变换乘积的反变换⽽得:反之,在频域中的卷积、可由在空间域中乘积的傅⽴叶变换⽽得,即:频域滤波的基本步骤根据式(6-47)进⾏频域滤波通常应遵循以下步骤。
(1)计算原始图像f(x,y)的DFT,得到F(u, v).(2)将频谱F(u,v)的零频点移动到频谱图的中⼼位置。
(3)计算滤波器函数H(u, v)与F(u,v)的乘积G(u, v).(4)将频谱G(u, v)的零频点移回到频谱图的左上⾓位置。
(5)计算第(4)步计算结果的傅⽴叶反变换g(x,y)。
(6)取g(x,y )的实部作为最终滤波后的结果图像.由上⾯的叙述易知,滤波能否取得理想结果的关键取决于频域滤波函数H(u,v)。
我们常常称之为滤波器,或滤波器传递函数,因为它在滤波中抑制或滤除了频谱中某些频率的分量,⽽保留其他的⼀些频率不受影响。
本书中我们只关⼼值为实数的滤波器,这样滤波过程中H 的每⼀个实数元素分别乘以F中对应位置的复数元素,从⽽使F中元素的实部和虚部等⽐例变化,不会改变F的相位谱,这种滤波器也因此被称为“零相移” 滤波器。
这样,最终反变换回空域得到的滤波结果图像 g(x,y)理论上也应当为实函数,然⽽由于计算舍⼊误差等原因,可能会带有⾮常⼩的虚部,通常将虚部直接忽略。