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

% Last Modified by GUIDE v2.5 12-Nov-2023 17:38:17

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Garbage_sorting_OpeningFcn, ...
                   'gui_OutputFcn',  @Garbage_sorting_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
% End initialization code - DO NOT EDIT


% --- Executes just before Garbage_sorting is made visible.
function Garbage_sorting_OpeningFcn(hObject, eventdata, handles, varargin)
% 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 reserved - to be defined in a future version of MATLAB
% Choose default command line output for Garbage_sorting
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Garbage_sorting wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% 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 Garbage_sorting (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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

% --- Outputs from this function are returned to the command line.
function varargout = Garbage_sorting_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;
end

% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Open a dialog to select an image file
[filename, pathname] = uigetfile({".jpg";".png";"*.bmp"},"Select an image");
if isequal(filename,0)
disp("User selected Cancel");
else
% Read the selected image
handles.img = imread(fullfile(pathname, filename));

% Display the image in axes
axes(handles.axes10);
imshow(handles.img);

% Update handles structure
guidata(hObject, handles);
end
end
% hObject    handle to pushbutton13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

function binary_img = target_binary_extraction(img)
% 示例代码：将图像转换为灰度图像
gray_img = rgb2gray(img);

% 示例代码：根据阈值将灰度图像二值化
threshold = 128; % 设定阈值
binary_img = imbinarize(gray_img, threshold);
end

function processed_img = remove_small_areas(binary_img)
% 示例代码：去除小面积的连通区域
min_area = 200; % 设定最小面积阈值
processed_img = bwareaopen(binary_img, min_area);
end

function dot_product = perform_dot_product(binary_img)
% 示例代码：计算二值图像内白色像素点的个数
dot_product = sum(binary_img(:));
end

function segmented_img = target_segmentation(binary_img)
% 示例代码：将二值图像进行分割处理（这里示意性地用一个反色操作作为示例）
segmented_img = imcomplement(binary_img);
end



% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Check if an image has been loaded
if ~isfield(handles,"img")
warndlg("Please select an image first.","Warning");
return;
end
% Perform target binary extraction
binary_img = target_binary_extraction(handles.img);
% Display the binary image in axes
axes(handles.axes11);
imshow(binary_img);
% Update handles structure
handles.binary_img = binary_img;
guidata(hObject, handles);
end
% hObject    handle to pushbutton14 (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 pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Check if a binary image has been generated
if ~isfield(handles,"binary_img")
warndlg("Please perform target binary extraction first.","Warning");
return;
end
% Perform dot product
dot_product = perform_dot_product(handles.binary_img);
% Display the result in a dialog
msgbox(["The dot product result is:" ; num2str(dot_product)]);
end
% hObject    handle to pushbutton15 (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 pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton16 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Check if a binary image has been generated
if ~isfield(handles,"binary_img")
warndlg("Please perform target binary extraction first.","Warning");
return;
end
% Perform identification
identification_result = perform_identification(handles.binary_img);
% Display the result in a dialog
msgbox(["The identification result is: " identification_result]);
end
% hObject    handle to pushbutton16 (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 radiobutton7.
function pushbutton17_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton17 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Check if a binary image has been generated
if ~isfield(handles,"binary_img")
warndlg("Please perform target binary extraction first.","Warning");
return;
end
% Remove small areas
processed_img = remove_small_areas(handles.binary_img);
% Display the processed image in axes
axes(handles.axes12);
imshow(processed_img);
end
% hObject    handle to radiobutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton7


% --- Executes on button press in radiobutton8.
function radiobutton8_Callback(hObject, eventdata, handles)
end
% hObject    handle to radiobutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton8


% --- Executes on button press in radiobutton9.
function radiobutton9_Callback(hObject, eventdata, handles)
end
% hObject    handle to radiobutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton9


% --- Executes on button press in pushbutton18.
function pushbutton18_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton18 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Check if a binary image has been generated
if ~isfield(handles,"binary_img")
warndlg("Please perform target binary extraction first.","Warning");
return;
end
% Segment the target
segmented_img = target_segmentation(handles.binary_img);
% Display the segmented image in axes
axes(handles.axes13);
imshow(segmented_img);
end
% hObject    handle to pushbutton18 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
出现报错：函数或变量 'perform_identification' 无法识别。请修改代码来解决报错