编程语言
首页 > 编程语言> > 【图像去噪】基于matlab高通+低通+带通+方向滤波器图像滤波【含Matlab源码 1209期】

【图像去噪】基于matlab高通+低通+带通+方向滤波器图像滤波【含Matlab源码 1209期】

作者:互联网

一、简介

基于matlab高通+低通+带通+方向滤波器图像滤波

二、源代码

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

% Last Modified by GUIDE v2.5 15-Jun-2021 17:04:53

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ImageFilter_OpeningFcn, ...
                   'gui_OutputFcn',  @ImageFilter_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 ImageFilter is made visible.
function ImageFilter_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 ImageFilter (see VARARGIN)
global bIsFileOpen RImage
% Choose default command line output for ImageFilter
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ImageFilter wait for user response (see UIRESUME)
% uiwait(handles.figure1);
bIsFileOpen = false;
RImage = 0;

% --- Outputs from this function are returned to the command line.
function varargout = ImageFilter_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 pushbutton_refresh.
function pushbutton_refresh_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_refresh (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global bIsFileOpen  Image  RImage             %文件是否打开,全局变量,影像数组
if(~bIsFileOpen)
    return;
end
popup_sel_index = get(handles.popupmenu_sel, 'Value');
scale = get(handles.slider1,'Value');

switch popup_sel_index
    case 1
        PQ = paddedsize(size(Image));
        D0 = scale*PQ(1);
        H = hpfilter('gaussian',PQ(1),PQ(2),D0);
        H1 = ifftshift(H);
        RImage = dftfilt(Image,H);
        RImage = im2uint8(mat2gray(RImage));
        axes(handles.axes_outputImage);
        imshow(RImage);
        axes(handles.axes_filter);
        imshow(H1);
    case 2
        PQ = paddedsize(size(Image));
        D0 = scale*PQ(2);
        H = lpfilter('gaussian',PQ(1),PQ(2),D0);
        H1 = ifftshift(H);
        RImage = dftfilt(Image,H);
        RImage = im2uint8(mat2gray(RImage));
        axes(handles.axes_outputImage);
        imshow(RImage);
        axes(handles.axes_filter);
        imshow(H1);
    case 3
        scale1 = str2double(get(handles.edit_FilterPara2,'String') );
        PQ = paddedsize(size(Image));
        D1 = scale*PQ(1);
        D2 = scale1*PQ(1);
        H = bandfilter(PQ(1),PQ(2),D1,D2);
        H1 = ifftshift(H);
        RImage = dftfilt(Image,H);
        RImage = im2uint8(mat2gray(RImage));
        axes(handles.axes_outputImage);
        imshow(RImage);
        axes(handles.axes_filter);
        imshow(H1); 
    case 4
        scale1 = -90 + str2double(get(handles.edit_FilterPara2,'String') );
        PQ = paddedsize(size(Image));
        D1 = floor(2*scale*PQ(1));
        D2 = scale1;
        H = tapefilter(PQ(1),PQ(2),D1,D2);
        H1 = fftshift(H);
        RImage = dftfilt(Image,H1);
        RImage = im2uint8(mat2gray(RImage));
        axes(handles.axes_outputImage);
        imshow(RImage);
        axes(handles.axes_filter);
        imshow(H); 
end
FImage = log(1+abs(fft2(Image)));
FUImage =  fftshift(im2uint8(mat2gray(FImage)));
axes(handles.axes_inputFreq);
imshow(FUImage);

FRImage = log(1+abs(fft2(RImage)));
FURImage =  fftshift(im2uint8(mat2gray(FRImage)));
axes(handles.axes_OutputFreq);
imshow(FURImage);
difImage = im2uint8(double(RImage)-double(Image));
axes(handles.axes_diffImage);
imshow(difImage);
% --- Executes during object creation, after setting all properties.
function popupmenu_sel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu_sel (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 popupmenu_sel.
function popupmenu_sel_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu_sel (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 popupmenu_sel contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu_sel
popup_sel_index = get(handles.popupmenu_sel, 'Value');
switch(popup_sel_index)
    case 1
        set(handles.edit_FilterPara2,'String','0');
        set(handles.edit_FilterPara2,'Enable','off');
        set(handles.text_para1,'string','滤波圆半径');
        set(handles.text_para2,'string','');
    case 2
        set(handles.edit_FilterPara2,'String','0');
        set(handles.edit_FilterPara2,'Enable','off');
        set(handles.text_para1,'string','滤波圆半径');
        set(handles.text_para2,'string','');
    case 3
        set(handles.edit_FilterPara2,'Enable','on');
        set(handles.text_para1,'string','滤波圆1半径');
        set(handles.text_para2,'string','滤波圆2半径');
        scale = get(handles.slider1,'Value');
        set(handles.edit_FilterPara2,'String',scale+0.1);
    case 4
        set(handles.edit_FilterPara2,'String',90);
        set(handles.edit_FilterPara2,'Enable','on');
        set(handles.text_para1,'string','滤波宽度');
        set(handles.text_para2,'string','旋转角度');
end


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

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(  handles.edit_FilterPara,'String',num2str( get(hObject,'Value') )  );
set(  handles.edit_FilterPara2,'String',num2str( get(hObject,'Value')+0.1 )  )

% --- Executes on button press in pushbutton_Input.
function pushbutton_Input_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_Input (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global bIsFileOpen  Image    Scale               %文件是否打开,全局变量,影像数组
[filename, pathname] = uigetfile( ...
{'*.bmp;*.jpg;*.jpeg;','图像文件 (*.bmp;*.jpg;*.jpeg)';
    '*.bmp',  '位图文件 (*.bmp)'; ...
    '*.jpg','jpeg图像文件 (*.jpg)'; ...
    '*.jpeg','jpeg图像文件 (*.jpeg)'; ...
}, '选择一个文件');                         %文件打开对话框

if ~isequal(filename, 0)                    %文件存在
    FileFullname=strcat(pathname,filename); %全名
    Image = imread(FileFullname);           %读入图像,Image
    if(size(Image,3)~=1)
        errordlg('目前只支持256色图像!');
        bIsFileOpen = false;                     %文件打开
        return;
    end
    bIsFileOpen = true;                     %文件打开
    axes(handles.axes_inputImage);          %axes_InputImage
    imshow(Image);                          %在 axes_Image 中显示左图
    set(handles.slider1,'Value',0.1);
    set(handles.edit_FilterPara,'String',0.1);
    set(handles.edit_FilterPara2,'String',0.2);
end


% --- Executes on button press in pushbutton_Output.
function pushbutton_Output_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_Output (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global RImage
if(size(RImage)==1)
    return
end

三、运行结果

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

四、备注

版本:2014a

标签:图像去噪,set,1209,see,axes,handles,hObject,源码,RImage
来源: https://www.cnblogs.com/QQ912100926/p/15127674.html