0
点赞
收藏
分享

微信扫一扫

【图像增强】基于自适应空域滤波图像增强含Matlab源码

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});
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 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 ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function 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 ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function 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 ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function 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
% val = get(handles.noise_pop_menu,'value');
% str = get(handles.noise_pop_menu,'string');
% switch str{val}
% case '高斯噪声'
% set(handles.m_edit,'enable','on');
% set(handles.v_edit,'enable','on');
% g = imnoise(img,'gaussian',m,v);
% case '椒盐噪声'
% set(handles.m_edit,'enable','on');
% g = imnoise(img,'salt & pepper',v);
% set(handles.v_edit,'enable','off');
% case '乘性噪声'
% set(handles.v_edit,'enable','on');
% g = imnoise(img,'speckle',v);
% set(handles.m_edit,'enable','off');
% case '泊松噪声'
% g = imnoise(img,'poisson');
% set(handles.m_edit,'enable','off');
% set(handles.v_edit,'enable','off');
% end
axes(handles.axes3);
imshow(f);
else
errordlg({'请输入有效整数';
' C > 0'},'error');%弹出错误提示对话框
end
% --- Executes on button press in close_button.
function close_button_Callback(hObject, eventdata, handles)
% hObject handle to close_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(spatial_filter);
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (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 listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function noise_pop_menu_CreateFcn(hObject, eventdata, handles)
% hObject handle to noise_pop_menu (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 noise_pop_menu.
function noise_pop_menu_Callback(hObject, eventdata, handles)
% hObject handle to noise_pop_menu (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'));
set(handles.m_edit,'enable','on');
set(handles.v_edit,'enable','on');
img = getimage(handles.axes1);
val = get(hObject,'value');
str = get(hObject,'string');
switch str{val}
case '高斯噪声'
set(handles.m_edit,'string','0.0');
set(handles.v_edit,'string','0.01');
m = 0.0;
v = 0.01;
g = imnoise(img,'gaussian',m,v);
case '椒盐噪声'
set(handles.v_edit,'string','0.05');
v = 0.05;
g = imnoise(img,'salt & pepper',v);
set(handles.m_edit,'enable','off');
case '乘性噪声'
set(handles.v_edit,'string','0.04');
v = 0.04;
g = imnoise(img,'speckle',v);
set(handles.m_edit,'enable','off');
case '泊松噪声'
g = imnoise(img,'poisson');
set(handles.m_edit,'enable','off');
set(handles.v_edit,'enable','off');
end
axes(handles.axes1);
imshow(img);
axes(handles.axes2);
imshow(g);
w = fspecial('average',[3,3]);
f = imfilter(g,w);
axes(handles.axes3);
imshow(f);
% Hints: contents = get(hObject,'String') returns noise_pop_menu contents as cell array
% contents{get(hObject,'Value')} returns selected item from noise_pop_menu
% --- Executes during object creation, after setting all properties.
function filter_pop_menu_CreateFcn(hObject, eventdata, handles)
% hObject handle to filter_pop_menu (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 filter_pop_menu.
function filter_pop_menu_Callback(hObject, eventdata, handles)
% hObject handle to filter_pop_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%

3 仿真结果

【图像增强】基于自适应空域滤波图像增强含Matlab源码_图像增强

4 参考文献

[1]楚智媛,吕闯. 基于MATLAB下空域滤波算法的图像增强[J]. 中国科技信息, 2020(19):2.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

【图像增强】基于自适应空域滤波图像增强含Matlab源码_图像增强_02




举报

相关推荐

0 条评论