一、图像去噪及滤波简介

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模型就是这一类。这类方法的关键是找到合适的能量方程,保证演化的稳定性,获得理想的结果。

形态学噪声滤除器将开与闭结合可用来滤除噪声,首先对有噪声图像进行开运算,可选择结构要素矩阵比噪声尺寸大,因而开运算的结果是将背景噪声去除;再对前一步得到的图像进行闭运算,将图像上的噪声去掉。据此可知,此方法适用的图像类型是图像中的对象尺寸都比较大,且没有微小细节,对这类图像除噪效果会较好。

3 离散余弦变换

考虑图像中加入高斯白噪声,其观测模型为

【图像去噪】基于matlab GUI DCT图像去噪【含Matlab源码 614期】_去噪

式中:y———加入噪声的图像,x———原图像,e———均值为0,方差为σ2的高斯白噪声。

通过离散余弦变换将图像变换到频域得到图像的频域信息。考虑M×M的图像块,可以得到其频域系数为

【图像去噪】基于matlab GUI DCT图像去噪【含Matlab源码 614期】_图像去噪_02

离散余弦变换具有很强的“能量集中性”,矩阵中左上角的系数代表了图像的大部分信息,右下角的系数则反映了其细节和噪声信息,仅对右下角的系数进行阈值收缩即可达到去噪的目的。

采用离散余弦变换对图像进行去噪是一种简单有效的方法。将图像从时域变换到频域后可以获得一系列的频域系数, 对这些DCT系数进行阈值收缩后再进行离散余弦反变换就可以得到去噪后的图像。因此对于频域系数的处理方法大大影响着去噪的效果,阈值选择过小,会保留下很多噪声,阈值选择过大;则会模糊掉大量的图像细节信息。因此,在噪声水平较高时,这种方法的去噪效果并不理想。

二、部分源代码

function varargout = imDCT(varargin)
% IMDCT M-file for imDCT.fig
% IMDCT, by itself, creates a new IMDCT or raises the existing
% singleton*.
%
% H = IMDCT returns the handle to a new IMDCT or the handle to
% the existing singleton*.
%
% IMDCT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMDCT.M with the given input arguments.
%
% IMDCT('Property','Value',...) creates a new IMDCT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before imDCT_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to imDCT_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 imDCT

% Last Modified by GUIDE v2.5 07-Dec-2009 19:54:09

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @imDCT_OpeningFcn, ...
'gui_OutputFcn', @imDCT_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(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 imDCT is made visible.
function imDCT_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 imDCT (see VARARGIN)

% Choose default command line output for imDCT
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes imDCT wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = imDCT_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;



function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
ImgPath=get(handles.edit1,'String');
CompressRate=uint8(fix(str2num(get(handles.edit2,'String'))));
if CompressRate>64
CompressRate=64;
end
if CompressRate<1
CompressRate=1;
end
set(handles.edit2,'String',num2str(CompressRate));
img=imread(ImgPath);
axes(handles.axes1);
imshow(img);
set(handles.text7,'Visible','off');
set(handles.text7,'String','处理状态:正在处理中...');
set(handles.text7,'Visible','on');
pause(0.1);
Block=ceil(size(img)/8);
ImgDCT=zeros(Block*8);
ImgRestoreTemp=zeros(Block*8);
ImgRestore=zeros(size(img));
ImgBlock=zeros(8);
DCTBlock=zeros(8);
vector=zeros(1,64);
for ii=1:Block(1)
for jj=1:Block(2)
ImgBlock(:,:)=zeros(8);
if ii==Block(1)
if jj==Block(2)
ImgBlock(1:size(img,1)-(ii-1)*8,1:size(img,2)-(jj-1)*8)=img((ii-1)*8+1:size(img,1),(jj-1)*8+1:size(img,2));
else
ImgBlock(1:size(img,1)-(ii-1)*8,:)=img((ii-1)*8+1:size(img,1),(jj-1)*8+1:jj*8);
end
else
if jj==Block(2)
ImgBlock(:,1:size(img,2)-(jj-1)*8)=img((ii-1)*8+1:ii*8,(jj-1)*8+1:size(img,2));
else
ImgBlock(:,:)=img((ii-1)*8+1:ii*8,(jj-1)*8+1:jj*8);
end
end
DCTBlock(:,:)=dct2(ImgBlock(:,:));
if CompressRate~=64
vector(1:64)=m2v(DCTBlock(:,:));
vector(CompressRate+1:64)=0;
DCTBlock(:,:)=v2m(vector(1:64));
end
ImgDCT((ii-1)*8+1:ii*8,(jj-1)*8+1:jj*8)=DCTBlock(:,:);
end
end

三、运行结果

【图像去噪】基于matlab GUI DCT图像去噪【含Matlab源码 614期】_频域_03