一、获取代码方式

获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

获取代码方式2:
完整代码已上传我的资源:【图像修复】基于matlab GUI空域滤波图像复原【含Matlab源码 849期】

备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、简介

空域滤波是一种邻域处理方法,通过直接在图像空间中对邻域内像素进行处理,达到平滑或锐化图像的作用。此外,在图像识别中,通过滤波还可以抽出图像的特征作为图像识别的特征模式。
空域滤波是图像处理领域中广泛使用的主要工具。空域滤波主要可以分为线性滤波和非线性滤波,其中,线性滤波和频域滤波存在一一对应的关系。但是,空域滤波可以用于非线性滤波,但是频域滤波不能用于非线性滤波。
从根源上讲,滤波这一词语来自于频域,信号处理中频域滤波指的是允许或者限制一定的频率成分通过。但空域滤波直接在图像空间中增强图像的某些特征或者减弱图像的某些特征。
空域滤波的作用域是像素及其邻域,通常使用空域模板对邻域内的像素进行处理从而产生该像素的输出值。
线性空域滤波指的是像素的输出值是计算该像素邻域内像素值的线性组合,系数矩阵在这里我们称之为模板。由信号处理的原理可以得出,线性滤波可以用卷积来实现。因此,在数字图像处理中,线性滤波通常是利用滤波模板与图像的空域进行卷积来实现的,在线性滤波中滤波模板也称为卷积模板。
根据空域卷积的定义可以知道,卷积首先需要将模板进行反褶,也就是将模板绕模板中心旋转180°,但是在数字图像处理中,卷积模板通常是关于原点对称的,因此通常不需要考虑反褶过程。模板卷积的主要步骤包括如下几个步骤,

(a.将模板在图像中进行遍历,将模板中心和各个像素位置重合;
(b.将模板的各个系数与模板对应像素值进行相乘;
(c.将所有的乘积相加,并将求和结果赋值于模板中心对应的像素
对于尺寸为m*n的模板,线性滤波在图像中像素(x,y)处的相应输出g(x,y)的一般表达式如下:


上式中,w(s,t)和f(x+s,y+t)分别为模板系数和模板对应像素,其中,为了保证唯一坐标s和t是整数,要求m和n是奇数。在一般情况下,线性滤波选取尺寸为奇数的正方形模板。

为了方便进行描述,设模板的尺寸为mxn,线性滤波在像素(x,y)处的相应输出R的另一种简单化表示为:

上式中wi表示的是模板系数,zi表示与模板系数对应的像素值,这里i = 1,2,3,…,mn,mn这里指的是模板对应的像素总数。

在非线性空域滤波中也是采用基于邻域的处理,而且模板滑过一幅图像的机理和线性空域滤波是一致的。非线性滤波处理也取决于模板对应的邻域内的像素,然而,因为不能直接利用上面g(x,y)的表达式计算乘积求和。例如非常有用的中值滤波,它是将模板对应的邻域内的像素值进行排序,然后查找中间值。利用这种方法可以有效地去除椒盐噪声,但是因为非线性滤波涉及到了像素值的排序操作,因此它的时间开销要比线性滤波的大。

对于实现空域滤波的最后一个问题是对于图像边界像素邻域的处理。对于尺寸为n*n的空域模板,当模板中心距离图像边界为(n-1)/2像素时,该模板正好在图像的内部。如果模板的中心继续像图像外边界靠近,那么模板的行或列就会超出图像之外。因此常常采用延拓的方式解决外边界问题。常用的方法有四种,分别是补零、重复、对称和循环方式,补零是指通过补零来扩展图像。重复是指通过复制外边界的值来扩展图像,对称是指通过镜像反射外边界的值来扩展图像,循环是指将图像看成二维周期函数的一个周期来扩展。在空域滤波完成后,从处理后的图像裁剪出与源图像对应的部分,使处理后的图像与源图像的尺寸相等。

三、部分源代码

function varargout = spatial_filter(varargin)
% SPATIAL_FILTER M-file for spatial_filter.fig
%      SPATIAL_FILTER, by itself, creates a new SPATIAL_FILTER or raises the existing
%      singleton*.
%
%      H = SPATIAL_FILTER returns the handle to a new SPATIAL_FILTER or the handle to
%      the existing singleton*.
%
%      SPATIAL_FILTER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SPATIAL_FILTER.M with the given input arguments.
%
%      SPATIAL_FILTER('Property','Value',...) creates a new SPATIAL_FILTER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before spatial_filter_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to spatial_filter_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 spatial_filter% Last Modified by GUIDE v2.5 31-May-2014 09:03:34% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...'gui_Singleton',  gui_Singleton, ...'gui_OpeningFcn', @spatial_filter_OpeningFcn, ...'gui_OutputFcn',  @spatial_filter_OutputFcn, ...'gui_LayoutFcn',  [] , ...'gui_Callback',   []);
if nargin & isstr(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT% --- Executes just before spatial_filter is made visible.
function spatial_filter_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 spatial_filter (see VARARGIN)
axes(handles.axes1);
img = imread('lena.bmp');
imshow(img);
[M,N] = size(img);
g = imnoise(img,'gaussian',0.05,0.01);
axes(handles.axes2);
imshow(g);
w = fspecial('average',[3,3]);
f = imfilter(g,w);
axes(handles.axes3);
imshow(f);
set(handles.m_edit,'string',0.05);
set(handles.v_edit,'string',0.01);
set(handles.c_edit,'string',3);
% Choose default command line output for spatial_filter
handles.output = hObject;% Update handles structure
guidata(hObject, handles);% UIWAIT makes spatial_filter wait for user response (see UIRESUME)
% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.
function varargout = spatial_filter_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 during object creation, after setting all properties.
function m_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to m_edit (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 ispcset(hObject,'BackgroundColor','white');
elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
endfunction m_edit_Callback(hObject, eventdata, handles)
% hObject    handle to m_edit (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 m_edit as text
%        str2double(get(hObject,'String')) returns contents of m_edit as a double% --- Executes during object creation, after setting all properties.
function v_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v_edit (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 ispcset(hObject,'BackgroundColor','white');
elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
endfunction v_edit_Callback(hObject, eventdata, handles)
% hObject    handle to v_edit (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 v_edit as text
%        str2double(get(hObject,'String')) returns contents of v_edit as a double% --- Executes during object creation, after setting all properties.
function c_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to c_edit (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 ispcset(hObject,'BackgroundColor','white');
elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
endfunction c_edit_Callback(hObject, eventdata, handles)
% hObject    handle to c_edit (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 c_edit as text
%        str2double(get(hObject,'String')) returns contents of c_edit as a double% --- Executes on button press in apply_button.
function apply_button_Callback(hObject, eventdata, handles)
% hObject    handle to apply_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% m = str2num(get(handles.m_edit,'string'));
% v = str2num(get(handles.v_edit,'string'));
c = str2num(get(handles.c_edit,'string'));
if c>0&&c==floor(c)&&size(c,1)*size(c,2)==1%c为整数且输入是‘一个’整数img = getimage(handles.axes1);
val1 = get(handles.filter_pop_menu,'value');
str1 = get(handles.filter_pop_menu,'string');
g = getimage(handles.axes2);
switch str1{val1}case '均值滤波器'w = fspecial('average',[c,c]);f = imfilter(g,w);case '中值滤波器'f = medfilt2(g,[c,c]);case '最大滤波器'f = ordfilt2(g,9,ones(c,c));case '最小滤波器'f = ordfilt2(g,1,ones(c,c));end

四、运行结果

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.

【图像修复】基于matlab GUI空域滤波图像复原【含Matlab源码 849期】相关推荐

  1. 【光学】基于matlab GUI杨氏双缝干涉【含Matlab源码 001期】

    一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[光学]基于matlab GUI杨氏双缝干涉[含Matlab源码 001期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: 付费 ...

  2. 【人脸识别】基于matlab GUI人数统计【含Matlab源码 2121期】

    ⛄一.人数统计简介(附课程作业报告) 1 课题背景 本课题为基于matlab的人数统计系统.近年来,很多行业对人流信息有极大的需求,如汽车公交站,地铁站台,商场出入口等.通过人数统计系统可以方便.可靠 ...

  3. 基于SSM的仓库管理系统(含完整源码+论文)

    后端框架:SSM 数据库:MySQL 开发工具:IDEA/Eclipse 系统介绍:本系统是基于SSM框架进行设计,MySQL作为底层数据库,前端采用bootstrap 模块大致介绍:包括库存管理.出 ...

  4. 【条形码识别】基于matlab GUI二维条形码识别【含Matlab源码 607期】

    ⛄一.二维条形码识别简介 采用数字图像处理技术对二维条码进行识别, 是二维条形码识别中较常用的方法, 它在处理污损的条形码方面有光电识别方法无法比拟的优势.另外图像式识别方法对识别角度的要求没有光电识 ...

  5. 【心电信号】基于matlab GUI心电信号预处理【含Matlab源码 938期】

    ⛄一.心电信号预处理方法简介 理论知识参考文献:心电信号预处理方法研究 ⛄二.部分源代码 function varargout = kaishi(varargin) gui_Singleton = 1 ...

  6. matlab svm 语音识别,【情感识别】基于matlab支持向量机(SVM)的语音情感识别【含Matlab源码 543期】...

    一.简介 支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本.非线性及高维模式识别中表现出许多特有的优势,并能够推广应用到函数 ...

  7. 【图像去噪】空域+频域滤波图像去噪【含GUI Matlab源码 914期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[图像去噪]基于matlab GUI空域+频域滤波图像去噪[含Matlab源码 914期] 获取代码方式2: 通过订阅紫极神光博客付费专栏 ...

  8. 【图像修复】基于matlab损坏图像修复【含Matlab源码 731期】

    一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[图像修复]基于matlab损坏图像修复[含Matlab源码 731期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: 付费专栏 ...

  9. 【图像融合】基于matlab导向滤波图像融合【含Matlab源码 1959期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[图像融合]基于matlab导向滤波图像融合[含Matlab源码 1959期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: ...

  10. 【图像去噪】基于matlab GUI butterworth+中值+维纳+小波图像去噪【含Matlab源码 520期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[图像去噪]基于matlab GUI butterworth+中值+维纳+小波图像去噪[含Matlab源码 520期] 获取代码方式2: ...

最新文章

  1. 深入理解 Vuejs 动画效果
  2. OPEN(SAP) UI5 扫盲
  3. 使用Google Cloud Storage托管您的Maven工件
  4. BurpSuite插件 -- Struts2-RCE
  5. idou老师教你学Istio 07: 如何用istio实现请求超时管理
  6. SpringMVC架构
  7. mysql的远程存储引擎_mysql的存储引擎之FEDERATED
  8. 卡尔曼滤波和粒子滤波最直白的解释
  9. protues7 使用笔记
  10. 小鹤输入法及练习工具推荐
  11. 第一次读 “Clean” 系列,并没有觉得这是一本多好的书
  12. 分享一个下载系统镜像的网站
  13. 博客已死?移动互联网时代博客的价值
  14. NLM(Non-Local means)算法原理
  15. 一个故事讲完进程、线程和协程
  16. js面向对象怎么理解
  17. CoAP学习笔记——CoAP格式详解
  18. 介紹HyperSnap使用方法!
  19. 【黑马程序员】C++核心编程2 -类与对象(封装、继承和多态)-this指针-友元-运算重载符-文本操作(附测试用例源码、测试结果图及详细注释)
  20. 基于python的串模式匹配

热门文章

  1. 基于stylus的border一像素线问题与ellipsis多行的兼容方案
  2. C#生成Guid,SqlServer生成Guid
  3. linux 用户操作相关命令
  4. ubuntu 安装cuda 成功
  5. Linux 中断下半部
  6. zngnqfxtuubuosmo
  7. spring快速入门(二)
  8. leapmotion 运行出错,看不到手势
  9. tinyxml读xml
  10. Atitit.视频文件加密的方法大的总结 java c# php