A list,
Nowadays, in commercial activities, quality testing is required before the fruit leaves the factory, and different grades of fruit need to be packaged in different grades to ensure the maximization of commercial benefits. However, the traditional methods rely on manual testing, which is inefficient and subjective, and cannot objectively evaluate the shipment quality, leading to the loss of profits of the factory, increasing customer complaints, resulting in the loss of brand efficiency, resulting in hidden losses. The subject is a fruit grading system based on MATLAB. Suitable for round fruit, such as apple, orange, grapefruit, persimmon, etc., statistical fruit picture area, roundness and color and other parameters for evaluation. The design comes with a GUI interface that tests these parameters by setting the diameter and color of the fruit, thus obtaining the grade of the fruit.
Ii. Source code
function varargout = appletest(varargin)
% APPLETEST MATLAB code for appletest.fig
% APPLETEST, by itself, creates a new APPLETEST or raises the existing
% singleton*.
%
% H = APPLETEST returns the handle to a new APPLETEST or the handle to
% the existing singleton*.
%
% APPLETEST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in APPLETEST.M with the given input arguments.
%
% APPLETEST('Property'.'Value',...). creates anew APPLETEST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before appletest_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to appletest_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 appletest
% Last Modified by GUIDE v2. 5 19-Oct- 2019. 20:28:04
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @appletest_OpeningFcn, ...
'gui_OutputFcn', @appletest_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 appletest is made visible.
function appletest_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 appletest (see VARARGIN)
% Choose default command line output for appletest
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes appletest wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = appletest_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)
[filename,pathname]=uigetfile({'*. *';'*.bmp';'*.jpg';'*.tif';'*.jpg'},'Select Image'); image=[pathname,filename]; % composition path + file name im=imread(image); Im =im2double(im); axes(handles.axes1); imshow(im); % display original image title at coordinates axes1'Original image');
handles.X1=im;
guidata(hObject,handles);
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
Val=get(hObject,'Value')
strl=get(hObject,'string')
switch strl{Val};
case 'area'
x1=handles.X1;
w=rgb2gray(x1);
L=medfilt2(w);
level=graythresh(L);
bw=im2bw(L,level);
bw=imfill(~bw,'holes');
axes(handles.axes2);
imshow(bw);
title('Area graph');
strNC=[num2str(bwarea(bw))];
set(handles.text9,'string',strNC);
strNC1=('First grade fruit');
strNC2=('Second order fruit');
strNC3=('Tertiary fruit');
if bwarea(bw)> 30000set(handles.text14,'string',strNC1);
else if bwarea(bw)>1000&&bwarea(bw)<30000
set(handles.text14,'string',strNC2);
else
set(handles.text14 ,'string',strNC3);
end
end
% strNC1=('no');
% set(handles.text14,'string',strNC1);
case'Color 'x1 = handles. X1; hv=rgb2hsv(x1); H=hv(:,:,1);
S=hv(:,:,2);
V=hv(:,:,3);
axes(handles.axes3);
imshow(H)
title('H component image ');
level=graythresh(x1);
apple=im2bw(x1,level);
count=length(x1);
for i=1:count
red_ratio=length(find((H>0 & H<1/12) | H>11/12))/length(find(apple==1));
end
r=red_ratio;
strNC=[num2str(red_ratio*100),The '%'];
set(handles.text10,'string',strNC);
strNC1=('First grade fruit');
strNC2=('Second order fruit');
strNC3=('Tertiary fruit');
if r>1
set(handles.text15,'string',strNC1);
else if r>0.8&&r<1
set(handles.text15,'string',strNC2);
else
set(handles.text15 ,'string',strNC3);
end
end
case'X1 =handles.X1; I2=rgb2gray(x1); J=im2bw(I2,0.75); I=~J; %==== morphological eigenvalue calculation ===% l=bwlabel(I,8);
[l,num]=bwlabel(I,8);
STATS=regionprops(l,'Area');
A=STATS.Area;
STATS=regionprops(l,'Perimeter');
L=STATS.Perimeter
C=(4.*pi.*A)./(L.*L); StrNC =[num2str(C)]; strNC=[num2str(C)];set(handles.text12,'string',strNC);
strNC1=('First grade fruit');
strNC2=('Second order fruit');
strNC3=('Tertiary fruit');
if C>0.65
set(handles.text17,'string',strNC1);
else if C>0.55&&C<0.65
set(handles.text17,'string',strNC2);
else
set(handles.text17,'string',strNC3);
end
end
case'X1 =handles.X1; w=rgb2gray(x1); L=medfilt2(w); level=graythresh(L); bw=im2bw(L,level); X=imclearborder(bw,4); % remove axes(handles. Axes4) from the area connected to the border but brighter; imshow(X) title('Defect image');
Q=(bwarea(X)/bwarea(~bw)*100)
q=num2str(bwarea(X)/bwarea(~bw)*100)
strNC=[q,The '%'];
set(handles.text11,'string',strNC);
strNC1=('First grade fruit');
strNC2=('Second order fruit');
strNC3=('Tertiary fruit');
if Q<0.1
set(handles.text16,'string',strNC1);
else if Q>0.1&&Q<0.2
set(handles.text16,'string',strNC2);
else
set(handles.text16,'string',strNC3);
end
end
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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
Copy the code
3. Operation results
Fourth, note
Version: 2014a complete code or write plus 1564658423