function varargout = ImageSegmentation(varargin)
% IMAGESEGMENTATION MATLAB code for ImageSegmentation.fig
% IMAGESEGMENTATION, by itself, creates a new IMAGESEGMENTATION or raises the existing
% singleton*.
%
% H = IMAGESEGMENTATION returns the handle to a new IMAGESEGMENTATION or the handle to
% the existing singleton*.
%
% IMAGESEGMENTATION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGESEGMENTATION.M with the given input arguments.
%
% IMAGESEGMENTATION('Property','Value',...) creates a new IMAGESEGMENTATION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ImageSegmentation_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ImageSegmentation_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 ImageSegmentation
% Last Modified by GUIDE v2.5 20-Apr-2016 13:59:55
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ImageSegmentation_OpeningFcn, ...
'gui_OutputFcn', @ImageSegmentation_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
function InitAxes(handles)
% 清理
clc;
% 坐标系设置
axes(handles.axes1); cla reset;
set(handles.axes1, 'XTick', [], 'YTick', [], ...
'XTickLabel', '', 'YTickLabel', '', 'Color', [0.7020 0.7804 1.0000], 'Box', 'On');
% 坐标系设置
axes(handles.axes2); cla reset;
set(handles.axes2, 'XTick', [], 'YTick', [], ...
'XTickLabel', '', 'YTickLabel', '', 'Color', [0.7020 0.7804 1.0000], 'Box', 'On');
function filePath = OpenFile(imgfilePath)
% 打开文件
% 输出参数:
% filePath——文件路径
if nargin < 1
% 设置默认参数
imgfilePath = fullfile(pwd, 'images/lena.bmp');
end
% 选择文件对话框
[filename, pathname, filterindex] = uigetfile( ...
{ '*.bmp','All bmp Files';...
'*.jpg','All jpg Files';...
'*.*', '所有文件 (*.*)'}, ...
'选择文件', ...
'MultiSelect', 'off', ...
imgfilePath);
% 初始化
filePath = 0;
if isequal(filename, 0) || isequal(pathname, 0)
% 如果选择无效
return;
end
% 整合路径
filePath = fullfile(pathname, filename);
% --- Executes just before ImageSegmentation is made visible.
function ImageSegmentation_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 ImageSegmentation (see VARARGIN)
% Choose default command line output for ImageSegmentation
handles.output = hObject;
% 初始化
InitAxes(handles);
handles.I_origin = 0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ImageSegmentation wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ImageSegmentation_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% 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)
% 选择文件
filePath = OpenFile();
if isequal(filePath, 0)
% 如果选择文件无效
return;
end
% 读取
I_origin = imread(filePath);
% 显示
axes(handles.axes1);
imshow(I_origin, []);
title('原图像');
% 存储
handles.I_origin = I_origin;
guidata(hObject, handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% 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)
if isequal(handles.I_origin, 0)
% 如果没有图像
return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
% 逐层处理
I2(:,:,i) = edge(I1(:,:,i),'roberts');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('Robert边缘检测');
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% 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)
if isequal(handles.I_origin, 0)
% 如果没有图像
return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
% 逐层处理
I2(:,:,i) = edge(I1(:,:,i),'sobel');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('Sobel边缘检测');
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% 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)
if isequal(handles.I_origin, 0)
% 如果没有图像
return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
% 逐层处理
I2(:,:,i) = edge(I1(:,:,i),'prewitt');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('Prewitt边缘检测');
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% 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)
if isequal(handles.I_origin, 0)
% 如果没有图像
return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
% 逐层处理
I2(:,:,i) = edge(I1(:,:,i),'log');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('LoG边缘检测');
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% 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)
if isequal(handles.I_origin, 0)
% 如果没有图像
return;
end
% 初始化
I1 = handles.I_origin;
for i = 1 : size(I1, 3)
% 逐层处理
I2(:,:,i) = edge(I1(:,:,i),'canny');
end
% 归一化
I2 = mat2gray(I2);
% 显示
axes(handles.axes2);
imshow(I2, []);
title('Canny边缘检测');
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% 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)
if isequal(handles.I_origin, 0)
% 如果没有图像
return;
end
% 初始化
I_origin = handles.I_origin;
for ik = 1 : size(I_origin, 3)
% 逐层处理
I1 = I_origin(:,:,ik);
% 直方图统计
[count, x] = imhist(I1);
% 对直方图平滑,平滑1次
z = medfilt1(count, 10);
% 对直方图平滑,平滑2次
z = medfilt1(z, 10);
% 对直方图插值
xi = 0:0.1:length(x)-1;
% 样条插值
图像边缘检测与图像分割常用算法研究分析-含用户界面.zip
版权申诉
5星 · 超过95%的资源 168 浏览量
2023-05-07
11:47:51
上传
评论 2
收藏 835KB ZIP 举报
matlab科研中心
- 粉丝: 2w+
- 资源: 164
最新资源
- flowable-designer-5.22.0.zip
- threadmanager.cpp
- 腾讯云小程序 - 一站式开发与部署平台
- 基于JSP+Java+Servlet采用MVC模式开发的购物网站+源码(毕业设计&课程设计&项目开发)
- fastgestures安装包,模拟mac的触控板收拾,两指代表右击, 三指拖拽
- 基于组态王的升降式横移立体车库控制系统+源码(毕业设计&课程设计&项目开发)
- 基于python+Django和协同过滤算法的电影推荐系统+源码(毕业设计&课程设计&项目开发)
- 环境配置 vscode+jupyter
- 项目全部代码,还包含使用到的图片
- 项目全部代码,还包含使用到的图片
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页