【图像去噪】基于matlab高通+低通+带通+方向滤波器图像滤波【含Matlab源码 1209期】
一、图像去噪及滤波简介
1 图像去噪
1.1 图像噪声定义
噪声是干扰图像视觉效果的重要因素,图像去噪是指减少图像中噪声的过程。噪声分类有三种:加性噪声,乘性噪声和量化噪声。我们用f(x,y)表示图像,g(x,y)表示图像信号,n(x,y)表示噪声。
图像去噪是指减少数字图像中噪声的过程。现实中的数字图像在数字化和传输过程中常受到成像设备与外部环境噪声干扰等影响,称为含噪图像或噪声图像。去噪是图像处理研究中的一个重点内容。在图像的获取、传输、发送、接收、复制、输出等过程中,往往都会产生噪声,其中的椒盐噪声是比较常见的一种噪声,它属于加性噪声。
1.2 图像噪声来源
(1)图像获取过程中
图像传感器CCD和CMOS采集图像过程中受传感器材料属性、工作环境、电子元器件和电路结构等影响,会引入各种噪声。
(2)图像信号传输过程中
传输介质和记录设备等的不完善,数字图像在其传输记录过程中往往会受到多种噪声的污染。
1.3 噪声分类
噪声按照不同的分类标准可以有不同的分类形式:
基于产生原因:内部噪声,外部噪声。
基于噪声与信号的关系:
加性噪声:加性噪声和图像信号强度是不相关的,这类带有噪声的图像g可看成为理想无噪声图像f与噪声n之和:
g = f + n;
乘性嗓声:乘性噪声和图像信号是相关的,往往随图像信号的变化而变化,载送每一个象素信息的载体的变化而产生的噪声受信息本身调制。在某些情况下,如信号变化很小,噪声也不大。为了分析处理方便,常常将乘性噪声近似认为是加性噪声,而且总是假定信号和噪声是互相统计独立。
g = f + f*n
按照基于统计后的概率密度函数:
是比较重要的,主要因为引入数学模型这就有助于运用数学手段去除噪声。在不同场景下噪声的施加方式都不同,由于在外界的某种条件下,噪声下图像-原图像(没有噪声时)的概率密度函数(统计结果)服从某种分布函数,那么就把它归类为相应的噪声。下面将具体说明基于统计后的概率密度函数的噪声分类及其消除方式。
1.4 图像去噪算法的分类
(1)空间域滤波
空域滤波是在原图像上直接进行数据运算,对像素的灰度值进行处理。常见的空间域图像去噪算法有邻域平均法、中值滤波、低通滤波等。
(2)变换域滤波
图像变换域去噪方法是对图像进行某种变换,将图像从空间域转换到变换域,再对变换域中的变换系数进行处理,再进行反变换将图像从变换域转换到空间域来达到去除图像嗓声的目的。将图像从空间域转换到变换域的变换方法很多,如傅立叶变换、沃尔什-哈达玛变换、余弦变换、K-L变换以及小波变换等。而傅立叶变换和小波变换则是常见的用于图像去噪的变换方法。
(3)偏微分方程
偏微分方程是近年来兴起的一种图像处理方法,主要针对低层图像处理并取得了很好的效果。偏微分方程具有各向异性的特点,应用在图像去噪中,可以在去除噪声的同时,很好的保持边缘。偏微分方程的应用主要可以分为两类:一种是基本的迭代格式,通过随时间变化的更新,使得图像向所要得到的效果逐渐逼近,这种算法的代表为Perona和Malik的方程,以及对其改进后的后续工作。该方法在确定扩散系数时有很大的选择空间,在前向扩散的同时具有后向扩散的功能,所以,具有平滑图像和将边缘尖锐化的能力。偏微分方程在低噪声密度的图像处理中取得了较好的效果,但是在处理高噪声密度图像时去噪效果不好,而且处理时间明显高出许多。
(4)变分法
另一种利用数学进行图像去噪方法是基于变分法的思想,确定图像的能量函数,通过对能量函数的最小化工作,使得图像达到平滑状态,现在得到广泛应用的全变分TV模型就是这一类。这类方法的关键是找到合适的能量方程,保证演化的稳定性,获得理想的结果。
形态学噪声滤除器将开与闭结合可用来滤除噪声,首先对有噪声图像进行开运算,可选择结构要素矩阵比噪声尺寸大,因而开运算的结果是将背景噪声去除;再对前一步得到的图像进行闭运算,将图像上的噪声去掉。据此可知,此方法适用的图像类型是图像中的对象尺寸都比较大,且没有微小细节,对这类图像除噪效果会较好。
2 频域滤波
2.1 主要步骤:空域(傅里叶变换、卷积)>>>频域(与转移函数相乘、处理、傅里叶反变换)>>>空域
2.2 常用频域增强方法:
巴特沃斯滤波器:阶为n,截断频率为D0的转移函数为:
(1)低通滤波:
低通巴特沃斯滤波器在高低频率间的过渡比较光滑,所以得到的输出图其“振铃”现象不明显。
频域低通滤波器能消除虚假轮廓。
(2)高通滤波:
就是利用滤波器的频率特性,让高频的通过,低频的无法通过,就好比在频率域设置阈值,频率域每一个频率分量有一个“幅值”,滤波器就好比在不同的频率分量给这个幅值乘以不同的增益,高通就好比高频部分增益为1,低频部分增益为0,当然这是理想高通。高斯高通滤波器就是频域每一个频率分量的增益的连接而成的曲线是一个高斯曲线
高通巴特沃斯滤波器.
G( x, y ) = g ( x, y ) + c * f( x, y ) c = 0.5,0<=c<=1
(3)带通和带阻滤波
带阻滤波器:阻止一定频率范围内的信号通过而允许其他频率范围内的信号通过。
带通滤波器:允许一定频率范围内的信号通过而阻止其它频率范围内的信号通过。带通和带阻互补。
低通、高通、带通、带阻等线性滤波器可以较好地消除线性叠加在图像上的加性噪声。但实际中,噪声和图像也常常是以非线性的方式结合。例如光源照明成像的情况,其中光的入射和景物的反射是以相乘的形式对成像做出贡献的,这样成像中的噪声与景物也是相乘的关系。
(4)同态滤波:
是一种在频域中同时将图像亮度范围进行压缩和将图像对比度进行增强的方法。
二、部分源代码
function varargout = ImageFilter(varargin)
% IMAGEFILTER M-file for ImageFilter.fig
% IMAGEFILTER, by itself, creates a new IMAGEFILTER or raises the existing
% singleton*.
%
% H = IMAGEFILTER returns the handle to a new IMAGEFILTER or the handle to
% the existing singleton*.
%
% IMAGEFILTER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGEFILTER.M with the given input arguments.
%
% IMAGEFILTER('Property','Value',...) creates a new IMAGEFILTER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ImageFilter_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ImageFilter_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help ImageFilter
% Last Modified by GUIDE v2.5 15-Jun-2021 17:04:53
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ImageFilter_OpeningFcn, ...
'gui_OutputFcn', @ImageFilter_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before ImageFilter is made visible.
function ImageFilter_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to ImageFilter (see VARARGIN)
global bIsFileOpen RImage
% Choose default command line output for ImageFilter
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ImageFilter wait for user response (see UIRESUME)
% uiwait(handles.figure1);
bIsFileOpen = false;
RImage = 0;
% --- Outputs from this function are returned to the command line.
function varargout = ImageFilter_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton_refresh.
function pushbutton_refresh_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_refresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global bIsFileOpen Image RImage %文件是否打开,全局变量,影像数组
if(~bIsFileOpen)
return;
end
popup_sel_index = get(handles.popupmenu_sel, 'Value');
scale = get(handles.slider1,'Value');
switch popup_sel_index
case 1
PQ = paddedsize(size(Image));
D0 = scale*PQ(1);
H = hpfilter('gaussian',PQ(1),PQ(2),D0);
H1 = ifftshift(H);
RImage = dftfilt(Image,H);
RImage = im2uint8(mat2gray(RImage));
axes(handles.axes_outputImage);
imshow(RImage);
axes(handles.axes_filter);
imshow(H1);
case 2
PQ = paddedsize(size(Image));
D0 = scale*PQ(2);
H = lpfilter('gaussian',PQ(1),PQ(2),D0);
H1 = ifftshift(H);
RImage = dftfilt(Image,H);
RImage = im2uint8(mat2gray(RImage));
axes(handles.axes_outputImage);
imshow(RImage);
axes(handles.axes_filter);
imshow(H1);
case 3
scale1 = str2double(get(handles.edit_FilterPara2,'String') );
PQ = paddedsize(size(Image));
D1 = scale*PQ(1);
D2 = scale1*PQ(1);
H = bandfilter(PQ(1),PQ(2),D1,D2);
H1 = ifftshift(H);
RImage = dftfilt(Image,H);
RImage = im2uint8(mat2gray(RImage));
axes(handles.axes_outputImage);
imshow(RImage);
axes(handles.axes_filter);
imshow(H1);
case 4
scale1 = -90 + str2double(get(handles.edit_FilterPara2,'String') );
PQ = paddedsize(size(Image));
D1 = floor(2*scale*PQ(1));
D2 = scale1;
H = tapefilter(PQ(1),PQ(2),D1,D2);
H1 = fftshift(H);
RImage = dftfilt(Image,H1);
RImage = im2uint8(mat2gray(RImage));
axes(handles.axes_outputImage);
imshow(RImage);
axes(handles.axes_filter);
imshow(H);
end
FImage = log(1+abs(fft2(Image)));
FUImage = fftshift(im2uint8(mat2gray(FImage)));
axes(handles.axes_inputFreq);
imshow(FUImage);
FRImage = log(1+abs(fft2(RImage)));
FURImage = fftshift(im2uint8(mat2gray(FRImage)));
axes(handles.axes_OutputFreq);
imshow(FURImage);
difImage = im2uint8(double(RImage)-double(Image));
axes(handles.axes_diffImage);
imshow(difImage);
% --- Executes during object creation, after setting all properties.
function popupmenu_sel_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu_sel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in popupmenu_sel.
function popupmenu_sel_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu_sel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu_sel contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu_sel
popup_sel_index = get(handles.popupmenu_sel, 'Value');
switch(popup_sel_index)
case 1
set(handles.edit_FilterPara2,'String','0');
set(handles.edit_FilterPara2,'Enable','off');
set(handles.text_para1,'string','滤波圆半径');
set(handles.text_para2,'string','');
case 2
set(handles.edit_FilterPara2,'String','0');
set(handles.edit_FilterPara2,'Enable','off');
set(handles.text_para1,'string','滤波圆半径');
set(handles.text_para2,'string','');
case 3
set(handles.edit_FilterPara2,'Enable','on');
set(handles.text_para1,'string','滤波圆1半径');
set(handles.text_para2,'string','滤波圆2半径');
scale = get(handles.slider1,'Value');
set(handles.edit_FilterPara2,'String',scale+0.1);
case 4
set(handles.edit_FilterPara2,'String',90);
set(handles.edit_FilterPara2,'Enable','on');
set(handles.text_para1,'string','滤波宽度');
set(handles.text_para2,'string','旋转角度');
end
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor',[.9 .9 .9]);
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set( handles.edit_FilterPara,'String',num2str( get(hObject,'Value') ) );
set( handles.edit_FilterPara2,'String',num2str( get(hObject,'Value')+0.1 ) )
% --- Executes on button press in pushbutton_Input.
function pushbutton_Input_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_Input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global bIsFileOpen Image Scale %文件是否打开,全局变量,影像数组
[filename, pathname] = uigetfile( ...
{'*.bmp;*.jpg;*.jpeg;','图像文件 (*.bmp;*.jpg;*.jpeg)';
'*.bmp', '位图文件 (*.bmp)'; ...
'*.jpg','jpeg图像文件 (*.jpg)'; ...
'*.jpeg','jpeg图像文件 (*.jpeg)'; ...
}, '选择一个文件'); %文件打开对话框
if ~isequal(filename, 0) %文件存在
FileFullname=strcat(pathname,filename); %全名
Image = imread(FileFullname); %读入图像,Image
if(size(Image,3)~=1)
errordlg('目前只支持256色图像!');
bIsFileOpen = false; %文件打开
return;
end
bIsFileOpen = true; %文件打开
axes(handles.axes_inputImage); %axes_InputImage
imshow(Image); %在 axes_Image 中显示左图
set(handles.slider1,'Value',0.1);
set(handles.edit_FilterPara,'String',0.1);
set(handles.edit_FilterPara2,'String',0.2);
end
% --- Executes on button press in pushbutton_Output.
function pushbutton_Output_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_Output (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global RImage
if(size(RImage)==1)
return
end
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
[5]基于matlab的传统算法图像去噪的实现原理
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/119601952
- 点赞
- 收藏
- 关注作者
评论(0)