图像去噪基于中值+小波+维纳+滤波器图像去噪matlab源码含 GUI

Posted 博主QQ2449341593

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像去噪基于中值+小波+维纳+滤波器图像去噪matlab源码含 GUI相关的知识,希望对你有一定的参考价值。

一、简介

1.1 中值滤波

     中值滤波是基于排序统计理论的一种能有效抑制噪声的非线性信号处理技术。它也是一种邻域运算,类似于卷积,但是计算的不是加权求和,而是把数字图像或数字序列中一点的值用该点的一个邻域中各点值的中值代替,让周围像素灰度值的差比较大的像素改取与周围的像素值接近的值,从而可以消除孤立的噪声点。它能减弱或消除傅立叶空间的高频分量,但影响低频分量。因为高频分量对应图像中的区域边缘的灰度值具有较大较快变化的部分,该滤波可将这些分量滤除,使图像平滑。值滤波技术在衰减噪声的同时能较好的保护图像的边缘。

1.2 均值滤波

均值滤波是指任意一点的像素值,都是周围 N \\times M 个像素值的均值。例如下图中,红色点的像素值是其周围蓝色背景区域像素值之和除25,25=5\\times5 是蓝色区域的大小。

均值滤波详细的计算方法如下图所示:

其中5\\times5的矩阵称为,针对原始图像内的像素点,采用核进行处理,得到结果图像,如下图所示:

提取 1/25 可以将核转换为如下形式:

1.3 小波变换

小波滤波原理

         小波变换就是把某一基函数做位移后,求不同尺度下的小波函数与原始信号的内积,表达式如下:

其中,a>0,是尺度因子,隐含信号的频率信息,是平移因子,这样信号就被分解成一系列小波函数的叠加,这就是小波分解的过程。基本原理是:对于信号的不同频率部分,改变尺度值,相当于在时间轴上对信号进行压缩和伸展。尺度越大,表示分析的信号区间越长,那么在频域的分辨率就越低,这样可以获取信号的低频成分;反之可以得到信号的高频成分。小波变换可以得到一系列的小波系数,从中分析有用信号和噪声各自对应的部分,对小波系数进行适当的处理。小波重构就是用处理得到的新的系数来重构信号。

         小波进行滤波就是一个小波分解和重构的过程,其基本步骤如下:

u  选择合适的小波基函数

u  对信号进行指定层次的小波分解

u  对各分解层进行处理,得到新的小波系数

u  用新得到的系数进行小波重构(小波逆变换)

小波基函数的选择

         对于同样的信号,不同的基函数会得到不同的结果。在小波基函数选择的时候要结合信号本身的特点,也要清楚小波基函数选取的原则:

u  正交性:可以使分析简便,有利于信号的精确重构

u  对称性:对称的基函数使得小波滤波呈线性相位,信号不会失真,也可以提高算法的运行速度

u  紧支性:紧支集的长度决定着信号局部特性的好坏,紧支集越短的小波基函数,局部时频特征就越好,越有利于信号的瞬时检测

u  正则性:决定信号重构后的平滑性,会影响频域的分辨率,支集长度越长,正则性越好;

u  消失矩:基函数的消失矩越高,在高频的衰减也就越快,变换后信号的的能量越集中,可以保持良好的频域定域性。

二、部分代码

 
  1. function varargout = dsp1(varargin)

  2. % DSP1 MATLAB code for dsp1.fig

  3. % DSP1, by itself, creates a new DSP1 or raises the existing

  4. % singleton*.

  5. %

  6. % H = DSP1 returns the handle to a new DSP1 or the handle to

  7. % the existing singleton*.

  8. %

  9. % DSP1('CALLBACK',hObject,eventData,handles,...) calls the local

  10. % function named CALLBACK in DSP1.M with the given input arguments.

  11. %

  12. % DSP1('Property','Value',...) creates a new DSP1 or raises the

  13. % existing singleton*. Starting from the left, property value pairs are

  14. % applied to the GUI before dsp1_OpeningFcn gets called. An

  15. % unrecognized property name or invalid value makes property application

  16. % stop. All inputs are passed to dsp1_OpeningFcn via varargin.

  17. %

  18. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one

  19. % instance to run (singleton)".

  20. %

  21. % See also: GUIDE, GUIDATA, GUIHANDLES

  22. % Edit the above text to modify the response to help dsp1

  23. % Last Modified by GUIDE v2.5 21-Mar-2014 21:34:03

  24. % Begin initialization code - DO NOT EDIT

  25. gui_Singleton = 1;

  26. gui_State = struct('gui_Name', mfilename, ...

  27. 'gui_Singleton', gui_Singleton, ...

  28. 'gui_OpeningFcn', @dsp1_OpeningFcn, ...

  29. 'gui_OutputFcn', @dsp1_OutputFcn, ...

  30. 'gui_LayoutFcn', [] , ...

  31. 'gui_Callback', []);

  32. if nargin && ischar(varargin{1})

  33. gui_State.gui_Callback = str2func(varargin{1});

  34. end

  35. if nargout

  36. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

  37. else

  38. gui_mainfcn(gui_State, varargin{:});

  39. end

  40. % End initialization code - DO NOT EDIT

  41. % --- Executes just before dsp1 is made visible.

  42. function dsp1_OpeningFcn(hObject, eventdata, handles, varargin)

  43. % This function has no output args, see OutputFcn.

  44. % hObject handle to figure

  45. % eventdata reserved - to be defined in a future version of MATLAB

  46. % handles structure with handles and user data (see GUIDATA)

  47. % varargin command line arguments to dsp1 (see VARARGIN)

  48. setappdata(handles.figure1,'img1',0);

  49. setappdata(handles.figure1,'img2',0);

  50. setappdata(handles.figure1,'img3',0);

  51. %set(handles.myimage_compress,'Enable', 'off');

  52. set(handles.pushbutton_compress,'Enable', 'off');

  53. set(handles.menu_quzaodesc, 'Enable', 'off');

  54. set(handles.save, 'Enable', 'off');

  55. % Choose default command line output for dsp1

  56. handles.output = hObject;

  57. % Update handles structure

  58. guidata(hObject, handles);

  59. % UIWAIT makes dsp1 wait for user response (see UIRESUME)

  60. % uiwait(handles.figure1);

  61. % --- Outputs from this function are returned to the command line.

  62. function varargout = dsp1_OutputFcn(hObject, eventdata, handles)

  63. % varargout cell array for returning output args (see VARARGOUT);

  64. % hObject handle to figure

  65. % eventdata reserved - to be defined in a future version of MATLAB

  66. % handles structure with handles and user data (see GUIDATA)

  67. % Get default command line output from handles structure

  68. varargout{1} = handles.output;

  69. % --- Executes on selection change in popupmenu.

  70. function popupmenu_Callback(hObject, eventdata, handles)

  71. % hObject handle to popupmenu (see GCBO)

  72. % eventdata reserved - to be defined in a future version of MATLAB

  73. % handles structure with handles and user data (see GUIDATA)

  74. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu contents as cell array

  75. % contents{get(hObject,'Value')} returns selected item from popupmenu

  76. val = get(hObject,'Value');

  77. str = get(hObject, 'String');

  78. switch str{val};

  79. case '无' %

  80. img2=getappdata(handles.figure1,'img1');

  81. axes(handles.axes2);

  82. imshow(img2);

  83. setappdata(handles.figure1,'img2',img2);

  84. set(handles.pushbutton_listen, 'Enable', 'off');

  85. case '高斯噪声' %

  86. img2=getappdata(handles.figure1,'img1');

  87. img2 = imnoise(img2,'gaussian'); %加高斯噪声

  88. axes(handles.axes2);

  89. imshow(img2);

  90. setappdata(handles.figure1,'img2',img2);

  91. set(handles.menu_quzaodesc, 'Enable', 'on');

  92. set(handles.pushbutton_listen, 'Enable', 'on');

  93. case '椒盐噪声' %

  94. img2=getappdata(handles.figure1,'img1');

  95. img2 = imnoise(img2,'salt');

  96. axes(handles.axes2);

  97. imshow(img2);

  98. setappdata(handles.figure1,'img2',img2);

  99. set(handles.menu_quzaodesc, 'Enable', 'on');

  100. set(handles.pushbutton_listen, 'Enable', 'on');

  101. case '泊松噪声' %

  102. img2=getappdata(handles.figure1,'img1');

  103. img2 = imnoise(img2,'poisson');

  104. axes(handles.axes2);

  105. imshow(img2);

  106. setappdata(handles.figure1,'img2',img2);

  107. set(handles.menu_quzaodesc, 'Enable', 'on');

  108. set(handles.pushbutton_listen, 'Enable', 'on');

  109. case '斑点噪声speckle' %

  110. img2=getappdata(handles.figure1,'img1');

  111. img2 = imnoise(img2,'speckle');

  112. axes(handles.axes2);

  113. imshow(img2);

  114. setappdata(handles.figure1,'img2',img2);

  115. set(handles.menu_quzaodesc, 'Enable', 'on');

  116. set(handles.pushbutton_listen, 'Enable', 'on');

  117. end

  118. % --- Executes during object creation, after setting all properties.

  119. function popupmenu_CreateFcn(hObject, eventdata, handles)

  120. % hObject handle to popupmenu (see GCBO)

  121. % eventdata reserved - to be defined in a future version of MATLAB

  122. % handles empty - handles not created until after all CreateFcns called

  123. % Hint: popupmenu controls usually have a white background on Windows.

  124. % See ISPC and COMPUTER.

  125. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

  126. set(hObject,'BackgroundColor','white');

  127. end

  128. % --------------------------------------------------------------------

  129. function myfile_Callback(hObject, eventdata, handles)

  130. % hObject handle to myfile (see GCBO)

  131. % eventdata reserved - to be defined in a future version of MATLAB

  132. % handles structure with handles and user data (see GUIDATA)

  133. % --------------------------------------------------------------------

  134. function myfile_open_Callback(hObject, eventdata, handles)

  135. % hObject handle to myfile_open (see GCBO)

  136. % eventdata reserved - to be defined in a future version of MATLAB

  137. % handles structure with handles and user data (see GUIDATA)

  138. [filename, pathname] = uigetfile(...

  139. {'*.bmp;*.jpg; *.png; *.jpeg; ','Image Files(*.bmp,*.jpg,*.png,*.jpeg)';...

  140. '*.*', 'All Files(*.*)' }...

  141. , 'Pick an image');%打开文件 选择图像

  142. if isequal(filename,0) || isequal(pathname,0)

  143. return;%如 果点了“ 取 消”

  144. end

  145. axes(handles.axes1);%重要,在哪个坐标轴显示图像

  146. fpath = [pathname filename];%路径名和文件名

  147. img1 = imread(fpath);%读取图像

  148. imshow(img1);%显示图像

  149. setappdata(handles.figure1,'img1',img1);

  150. % --- Executes on selection change in popupmenu3.

  151. function popupmenu3_Callback(hObject, eventdata, handles)

  152. % hObject handle to popupmenu3 (see GCBO)

  153. % eventdata reserved - to be defined in a future version of MATLAB

  154. % handles structure with handles and user data (see GUIDATA)

  155. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array

  156. % contents{get(hObject,'Value')} returns selected item from popupmenu3

  157. img2=getappdata(handles.figure1,'img2');%加噪图像

  158. img1=getappdata(handles.figure1,'img1');%原始图像

  159. val = get(hObject,'Value');

  160. str = get(hObject, 'String');

  161. switch str{val};

  162. case '中值滤波'

  163. set(handles.uipanel_lowfilt, 'Visible', 'off');

  164. set(handles.uipanel_gausslow, 'Visible', 'off');

  165. set(handles.pushbutton_quzao, 'Visible', 'off');

  166. img3 = medfilt2(img2);%中值滤波

  167. setappdata(handles.figure1,'img3',img3);

  168. axes(handles.axes3);

  169. imshow(img3);

  170. PSNR = psnr2(img3, img1);

  171. str1 = strcat('psnr为: ' , num2str(PSNR) , 'db');

  172. set(handles.text3, 'string', str1); %显示PSNR值

  173. set(handles.save, 'Enable', 'on');

  174. % set(handles.myimage_compress,'Enable', 'on');

  175. set(handles.pushbutton_compress,'Enable', 'on');

  176. case '维纳滤波'

  177. set(handles.uipanel_lowfilt, 'Visible', 'off');

  178. set(handles.uipanel_gausslow, 'Visible', 'off');

  179. set(handles.pushbutton_quzao, 'Visible', 'off');

  180. img3 = wiener2(img2,[5,5]);

  181. setappdata(handles.figure1,'img3',img3);

  182. axes(handles.axes3);

  183. imshow(img3);

  184. PSNR = psnr2(img3, img1);

  185. str1 = strcat('psnr为: ' , num2str(PSNR) , 'db');

  186. set(handles.text3, 'string', str1);

  187. % set(handles.myimage_compress,'Enable', 'on');

  188. set(handles.pushbutton_compress,'Enable', 'on');

  189. set(handles.save, 'Enable', 'on');

三、运行结果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

四、参考文献及代码私信博主

以上是关于图像去噪基于中值+小波+维纳+滤波器图像去噪matlab源码含 GUI的主要内容,如果未能解决你的问题,请参考以下文章

图像去噪基于中值+小波+维纳+滤波器图像去噪matlab源码含 GUI

地震波滤波保边滤波傅氏变换干扰波去噪滤波基于小波分解和重建的干扰波去噪基于维纳滤波的去噪中值滤波视速度滤波

图像去噪均值滤波+中值滤波+高斯低通滤波+多种小波变换图像去噪matlab源码GUI

图像去噪基于matlab自适应布谷鸟算法优化维纳滤波器图像去噪含Matlab源码 1892期

图像去噪基于matlab GUI加权+绝对差分中值滤波图像去噪含Matlab源码 1880期

图像去噪基于matlab高斯+均值+中值+双边滤波图像去噪含Matlab源码 1872期