编程语言
首页 > 编程语言> > 【图像处理】基于matlab GUI数字图像处理【含Matlab源码 652期】

【图像处理】基于matlab GUI数字图像处理【含Matlab源码 652期】

作者:互联网

一、简介

基于matlab GUI数字图像处理:灰度化、二值化、中值滤波、低通滤波、均值滤波、高斯滤波、直方图、腐蚀、canny、sobel。

二、源代码

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

% Last Modified by GUIDE v2.5 22-Apr-2017 15:16:04

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @image_processing_OpeningFcn, ...
                   'gui_OutputFcn',  @image_processing_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 image_processing is made visible.
function image_processing_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 image_processing (see VARARGIN)

% Choose default command line output for image_processing
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes image_processing wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = image_processing_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
axis off;
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
    global M;
    ima_gray=image_gray(M);
    imshow(ima_gray);
% 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)


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
    global M;
    ima_gray=image_gray(M);
    [i,j]=size(ima_gray);
    prompt = {'请输入阈值:'};
    dlg_title = '提示';
    num_lines = 1;
    def = {'5'};
    value_i = inputdlg(prompt,dlg_title,num_lines);
    threshold_value=str2double(value_i);
    for a=1:i
        for b=1:j
            if ima_gray(a,b)<threshold_value
                ima_gray(a,b)=0;
            else
                ima_gray(a,b)=1;
            end
        end
    end
    ima_gray=mat2gray(ima_gray);
    imshow(ima_gray);
    
        
% 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)


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
    global M;
    ima_red=M(:,:,1);
    ima_green=M(:,:,2);
    ima_blue=M(:,:,3);
    img_red=mid_filter(ima_red,6);
    img_green=mid_filter(ima_green,6);
    img_blue=mid_filter(ima_blue,6);
    image(:,:,1)=img_red;
    image(:,:,2)=img_green;
    image(:,:,3)=img_blue;
    imshow(image);
    
    
% 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)


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
    global M;
    if size(M,1)<2;
        msgbox('请先打开图片');
    end
    ima_red=M(:,:,1);
    ima_green=M(:,:,2);
    ima_blue=M(:,:,3);
    processing_red=low_pass_filter(ima_red);
    processing_green=low_pass_filter(ima_green);
    processing_blue=low_pass_filter(ima_blue);
    image(:,:,1)=processing_red;
    image(:,:,2)=processing_green;
    image(:,:,3)=processing_blue;
    imshow(image);
        
% 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)


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
    global M;
    prompt = {'请输入滤波核大小:'};
    dlg_title = '提示';
    num_lines = 1;
    def = {'5'};
    value_i = inputdlg(prompt,dlg_title,num_lines);
    N=str2double(value_i);
    d=avg_filter(M,N);    
    imshow(d);
    
    
% 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)


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
    global M;
    %滤波核大小
    ima_red=M(:,:,1);
    ima_green=M(:,:,2);
    ima_blue=M(:,:,3);
    prompt = {'请输入滤波器大小:'};
    dlg_title = '提示';
    num_lines = 1;
    value_i = inputdlg(prompt,dlg_title,num_lines);
    N=str2double(value_i);
    sigma=1.7;
    img_red=image_gaussian(ima_red,sigma,N);
    img_green=image_gaussian(ima_green,sigma,N);
    img_blue=image_gaussian(ima_blue,sigma,N);
    img(:,:,1)=img_red;
    img(:,:,2)=img_green;
    img(:,:,3)=img_blue;
    imshow(img);
    
% 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)


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
    global M;
    ima_red=M(:,:,1);
    ima_green=M(:,:,2);
    ima_blue=M(:,:,3);
    histogram_red=histogram(ima_red);
    histogram_green=histogram(ima_green);
    histogram_blue=histogram(ima_blue);
    figure,
    subplot(1,3,1);plot(histogram_red),title('红色通道');
    xlim([0 255])
    subplot(1,3,2),plot(histogram_green),title('绿色通道');
    xlim([0 255])
    subplot(1,3,3),plot(histogram_blue),title('蓝色通道');
    xlim([0 255])
%     ima=imread('1.jpg');
%     ima_gaussian=image_gaussian(ima,2,500);
% 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)


% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)%每个通道不一样,不能按照一个通道来
    global M;
    ima_gray=image_gray(M);
    [i,j]=size(ima_gray);
    threshold_value=150;
    for a=1:i
        for b=1:j
            if ima_gray(a,b)<threshold_value
                ima_gray(a,b)=0;
            else
                ima_gray(a,b)=1;
            end
        end
    end

三、运行结果

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

四、备注

完整代码或者代写添加QQ 1564658423

标签:ima,see,数字图像处理,hObject,handles,源码,652,gui,image
来源: https://blog.csdn.net/TIQCmatlab/article/details/115318339