部分源代码
function varargout = ActiveCountorsGUI(varargin)
% ACTIVECOUNTORSGUI M-file for ActiveCountorsGUI.fig
% ACTIVECOUNTORSGUI, by itself, creates a new ACTIVECOUNTORSGUI or raises the existing
% singleton*.
%
% H = ACTIVECOUNTORSGUI returns the handle to a new ACTIVECOUNTORSGUI or the handle to
% the existing singleton*.
%
% ACTIVECOUNTORSGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ACTIVECOUNTORSGUI.M with the given input arguments.
%
% ACTIVECOUNTORSGUI('Property','Value',...) creates a new ACTIVECOUNTORSGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ActiveCountorsGUI_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ActiveCountorsGUI_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 NoiseLambdaText to modify the response to help ActiveCountorsGUI
% Last Modified by GUIDE v2.5 28-Jun-2021 11:26:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ActiveCountorsGUI_OpeningFcn, ...
'gui_OutputFcn', @ActiveCountorsGUI_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 ActiveCountorsGUI is made visible.
function ActiveCountorsGUI_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 ActiveCountorsGUI (see VARARGIN)
% Choose default command line output for ActiveCountorsGUI
handles.output = hObject;
% subplot('Position',[0.29,0.12,0.79,0.79]);
X=zeros(300,250,3);
X(:,:,2)=200;
imshow(uint8(X),'Parent',handles.Axes);
txt_hndl=zeros(1,2);
txt_hndl(1)=text(20,146,{
'Welcome to our GUI!',...
' ','1. Choose image file for segmentation,',' using ''Load Image File'' button.',...
' ','2. Choose noise model parameters in ',' ''Noise Model'' panel.',...
' ','3. Choose the Gaussian blur filter Sigma value in ',' ''Blur denoise panel''.',...
' ','4. Choose the color space and colr element in ',' ''Color space'' panel.',...
' ','5. Choose the contour based segmentation algorithm ',' to apply and set desired algorithm parameters.',...
' ','6. Choose your display settings in the',' ''Display Menu'' panel.',...
' ','7. Choose refresh rate of displayed images',' and save rate of saved images.',...
' ','8. Choose output path for saved images during',' algorithm application (default - current directory).',...
' ','9. Finally, press ''Run'' below, and enjoy the magic...'},...
'FontSize',12);
txt_hndl(2)=text(50,308,'\copyright Nikolay S. & Alex B.','FontSize',10,'FontAngle','italic','Color','r');
set(txt_hndl,'Units','Normalized');
set(txt_hndl,'FontUnits','Normalized');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ActiveCountorsGUI wait for user response (see UIRESUME)
% uiwait(handles.GUIfig);
% --- Outputs from this function are returned to the command line.
function varargout = ActiveCountorsGUI_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 GUIfig_CreateFcn(hObject, eventdata, handles)
% hObject handle to GUIfig (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in ShowContour.
clc;clear all;warning off;
fprintf('%s\n\n','Active Contours GUI started.');
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (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 popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function OutDir_CreateFcn(hObject, eventdata, handles)
% hObject handle to OutDir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
handles=guidata(hObject);
directory_name=cd; %default value is current directory
handles.OutDirPath=directory_name;
guidata(hObject,handles);
% --- Executes on button press in OutDir.
function OutDir_Callback(hObject, eventdata, handles)
% hObject handle to OutDir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles=guidata(hObject);
directory_name = uigetdir;
handles.OutDirPath=directory_name;
guidata(hObject,handles);
% --- Executes on button press in LoadFileButton.
function LoadFileButton_Callback(hObject, eventdata, handles)
% hObject handle to LoadFileButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles=guidata(hObject);
FilterSpec={'*.jpg;*.jpeg;*.gif;*.bmp;*.png;*.tiff;*.tif','Image Files (*.jpg;*.jpeg;*.gif;*.bmp;*.png;*.tiff;*.tif)'};
DialogTitle='Select image file';
[FileName,PathName] = uigetfile(FilterSpec,DialogTitle);
if (isequal(FileName,0))
disp('File could not be loaded');
return;
end
handles.ImageFileAddr=[PathName,FileName];
guidata(hObject,handles);
handles.ImageData=add_noise2image(hObject);
set([handles.AlgParamsPanel,handles.AlgTypePanel,handles.NoiseModelPanel,...
handles.DispMenuPanel,handles.RunPanel,handles.ColorSpacePanel,...
handles.BlurUipanel],'Visible','on');
% for each new image, demand a new mask definition
handles.UserMask=[];
set(handles.UserDefineMaskButton,'String','Define Mask');
guidata(hObject,handles);
function MiuAlgEdit_Callback(hObject, eventdata, handles)
% hObject handle to MiuAlgEdit (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 MiuAlgEdit as NoiseLambdaText
% str2num(get(hObject,'String')) returns contents of MiuAlgEdit as a double
handles=guidata(hObject);
set(hObject,'Value',str2num(get(hObject,'String'))); % set value property equal to string numerical value property
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function MiuAlgEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to MiuAlgEdit (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function NuAlgEdit_Callback(hObject, eventdata, handles)
% hObject handle to NuAlgEdit (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 NuAlgEdit as NoiseLambdaText
% str2num(get(hObject,'String')) returns contents of NuAlgEdit as a double
handles=guidata(hObject);
set(hObject,'Value',str2num(get(hObject,'String'))); % set value property equal to string numerical value property
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function NuAlgEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to NuAlgEdit (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function DeltaTAlgEdit_Callback(hObject, eventdata, handles)
% hObject handle to DeltaTAlgEdit (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 DeltaTAlgEdit as NoiseLambdaText
% str2num(get(hObject,'String')) returns contents of DeltaTAlgEdit as a double
handles=guidata(hObject);
set(hObject,'Value',str2num(get(hObject,'String'))); % set value property equal to string numerical value property
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function DeltaTAlgEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to DeltaTAlgEdit (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Lambda1AlgEdit_Callback(hObject, eventdata, handles)
% hObject handle to Lambda1AlgEdit (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 Lambda1AlgEdit as NoiseLambdaText
% str2num(get(hObject,'String')) returns contents of Lambda1AlgEdit as a double
handles=guidata(hObject);
set(hObject,'Value',str2num(get(hObject,'String'))); % set value property equal to string numerical value property
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Lambda1AlgEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Lambda1AlgEdit (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Lambda2AlgEdit_Callback(hObject, eventdata, handles)
% hObject handle to Lambda2AlgEdit (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 Lambda2AlgEdit as NoiseLambdaText
% str2num(get(hObject,'String')) returns contents of Lambda2AlgEdit as a double
handles=guidata(hObject);
set(hObject,'Value',str2num(get(hObject,'String'))); % set value property equal to string numerical value property
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Lambda2AlgEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Lambda2AlgEdit (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function NAlgEdit_Callback(hObject, eventdata, handles)
% hObject handle to NAlgEdit (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 NAlgEdit as NoiseLambdaText
% str2num(get(hObject,'String')) returns contents of NAlgEdit as a double
handles=guidata(hObject);
set(hObject,'Value',round(str2num(get(hObject,'String')))); % set value property equal to string numerical value property
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function NAlgEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to NAlgEdit (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
[5]陈浩,方勇,朱大洲,王成,陈子龙.基于蚁群算法的玉米植株热红外图像边缘检测[J].农机化研究. 2015,37(06)