【图像分割】基于阈值分类器实现草莓图像分割含Matlab源码

网友投稿 262 2022-09-08


【图像分割】基于阈值分类器实现草莓图像分割含Matlab源码

1 简介

图像分割是图像处理与理解,模式识别和人工智能等多个领域中非常关键的问题.现介绍了在MATLAB开发环境下,基于边缘检测与基于阈值的图像分割算法的仿真设计方法,为后续基于MATLAB的数字图像处理方面的教学,科研提供了参考.

2 部分代码

function varargout = untitled(varargin)% UNTITLED M-file for untitled.fig% UNTITLED, by itself, creates a new UNTITLED or raises the existing% singleton*.%% H = UNTITLED returns the handle to a new UNTITLED or the handle to% the existing singleton*.%% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in UNTITLED.M with the given input arguments.%% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before untitled_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to untitled_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 untitled% Last Modified by GUIDE v2.5 11-Jan-2013 13:05:10% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled_OpeningFcn, ... 'gui_OutputFcn', @untitled_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif 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 untitled is made visible.function untitled_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 untitled (see VARARGIN)% Choose default command line output for untitledhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes untitled wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = untitled_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 structurevarargout{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)global im;global str;[filename,pathname]=uigetfile_new({'*.*'},'选择训练图片...');str=[pathname filename];im=imread(str);axes(handles.axes1);imshow(im);% --- 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)global im1;global str1;[filename,pathname]=uigetfile_new({'*.*'},'选择测试图片...');str1=[pathname filename];im1=imread(str1);axes(handles.axes2);imshow(im1);% --- 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)global im;global im1;global str1;se1 = strel('disk',5);se2 = strel('square',16);thresh1 = 0.2;thresh2 = 0.01;imtra = im2double(im);rt = imtra(:,:,1);gt = imtra(:,:,2);bt = imtra(:,:,3);idxr1 = find(rt>0);idxg1 = find(gt>0);idxb1 = find(bt>0);mr1 = mean(rt(idxr1));mg1 = mean(gt(idxg1));mb1 = mean(bt(idxb1));clear idxr1 idxg1 idxb1 idxgr1;im1=imread(str1);I1 = im2double(im1);col = size(I1,2);rate = 1600/col;I1 = imresize(I1,rate);r1 = I1(:,:,1);g1 = I1(:,:,2);b1 = I1(:,:,3);[row1,col1] = size(r1);r1 = abs(r1 - mr1);g1 = abs(g1 - mg1);b1 = abs(b1 - mb1);% --- 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)clear allclcclose(gcf)

3 仿真结果

4 参考文献

[1]李小琦. 基于Matlab的图像阈值分割算法研究[J]. 软件导刊, 2014, 13(12):3.

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

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


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:#yyds干货盘点#python文本自动换行与填充
下一篇:# yyds干货盘点 # Python面向对象中的类变量,实例变量怎么来理解?
相关文章

 发表评论

暂时没有评论,来抢沙发吧~