1 简介
噪声在图像上常表现为一引起较强视觉效果的孤立像素点或像素块。一般,噪声信号与要研究的对象不相关,它以无用的信息形式出现,扰乱图像的可观测信息。通俗的说就是噪声让图像不清楚。【1】噪声主要来源于图像获取过程和图像信号传输过程,常见的噪声有高斯噪声、椒盐噪声、乘性噪声等。
高斯噪声:
高斯噪声是指它的概率密度函数服从高斯分布(即正态分布)的一类噪声。如果一个噪声,它的幅度分布服从高斯分布,而它的功率谱密度又是均匀分布的,则称它为高斯白噪声。高斯白噪声的二阶矩不相关,一阶矩为常数,是指先后信号在时间上的相关性。【1】在matlab软件中有专门的高斯噪声产生函数,所以不需要用到太复杂的计算步骤。可以使用imnoise函数并选择gaussian即可在图片中加入高斯噪声。
椒盐噪声:
椒盐噪声也称为脉冲噪声,是图像中经常见到的一种噪声,它是一种随机出现的白点或者黑点,可能是亮的区域有黑色像素或是在暗的区域有白色像素(或是两者皆有)。【1】椒盐噪声通常是来源于图像切割。同样的,椒盐噪声的产生在matlab中也有相应的产生函数。与高斯噪声加入的方式类似,在matlab中使用imnoise选择salt & pepper即可在图片中加入椒盐噪声。
均值滤波:
均值滤波是一种线性滤波算法,它是指在图像上对目标像素给一个模板,该模板包括了其周围的临近像素(以目标像素为中心的周围8个像素,构成一个滤波模板,即包括目标像素本身),再用模板中的全体像素的平均值来代替原来像素值。
在matlab函数库中有多种实现均值滤波的方法,有filter2函数、conv2函数以及fspecial 和 imfilter 函数配合使用。此次的均值滤波我选择的是fspecial和imfilter联用的方法。
中值滤波:
与均值滤波不同,中值滤波法是一种非线性平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值。在matlab中实现中值滤波的方法也较为简单,直接使用medfilt2函数即可实现。
GUI:
GUI全称是Graphical User Interface,即图形用户界面。在matlab中的GUI可以在界面上添加按键、滑动条、可编辑文本框、静态文本框、坐标区等等。其中,坐标区还可以用来作为图像的显示区域,配合按键可以实现一个按键对应一张图的操作。在GUI界面上添加好自己所需的部件之后可以对每个部件进行编程,以此来达到自己预期的功能。此次的实践中,我采用的是按键和坐标区相结合的方式来实现特定的按键对应特定操作,并且在实现完按键所具有的功能之后将所产生的图象显示在特定的坐标区,以此来实现一个按键对应一个操作之后的图像显示。
2 部分代码
function varargout = work(varargin)
% WORK MATLAB code for work.fig
% WORK, by itself, creates a new WORK or raises the existing
% singleton*.
%
% H = WORK returns the handle to a new WORK or the handle to
% the existing singleton*.
%
% WORK('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in WORK.M with the given input arguments.
%
% WORK('Property','Value',...) creates a new WORK or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before work_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to work_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 work
% Last Modified by GUIDE v2.5 14-Mar-2022 12:52:52
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @work_OpeningFcn, ...
'gui_OutputFcn', @work_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 work is made visible.
function work_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 work (see VARARGIN)
% Choose default command line output for work
handles.output = hObject;
handles.work1=[];
handles.work2=[];
handles.work3=[];
handles.work4=[];
?
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes work wait for user response (see UIRESUME)
% uiwait(handles.figure1);
?
% --- Outputs from this function are returned to the command line.
function varargout = work_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 pushbutton1.
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)
[imgfilename, imgpathname] = uigetfile({'*. jpg;*. png'},'选择一张图片' ) ;
if imgfilename
I = imread([imgpathname '\' imgfilename]);
axes (handles. axes1);
imshow (I)
handles.work1=I;
end
?
guidata (hObject,handles);
?
% --- 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)
M=rgb2gray(handles.work1);
axes (handles. axes2);
imshow (M)
handles.work2=M;
guidata (hObject,handles);
?
% --- 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)
GS=imnoise(handles.work2,'gaussian',0,0.06); %添加高斯噪声,均值为0,方差为0.06
axes (handles. axes3);
imshow (GS)
handles.work3=GS;
guidata (hObject,handles);
?
% --- 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)
H1=fspecial('average',[9,9]);
JZ1=imfilter(handles.work3,H1); %均值滤波
axes (handles. axes4);
imshow (JZ1);
guidata (hObject,handles);
?
% --- 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)
ZZ1=medfilt2(handles.work3); %中值滤波
axes (handles. axes5);
imshow (ZZ1);
guidata (hObject,handles);
?
% --- 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)
JY=imnoise(handles.work2,'salt & pepper',0.33); %添加椒盐噪声
axes (handles. axes6);
imshow (JY);
handles.work4=JY;
guidata (hObject,handles);
% --- 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)
H1=fspecial('average',[9,9]);
JZ2=imfilter(handles.work4,H1);
axes (handles. axes7);
imshow (JZ2);
guidata (hObject,handles);
% --- 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)
ZZ2=medfilt2(handles.work4);
axes (handles. axes8);
imshow (ZZ2);
guidata (hObject,handles);
?
?
?
% --- Executes on mouse press over figure background.
function figure1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
?
% --- Executes on mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
?
3 仿真结果
4 参考文献
[1]胡鹏, 徐会艳. 基于Matlab的图像去噪算法的研究与实现[J]. 福建电脑, 2009(12):2.?
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。