1 简介
基于形态学算法实现自助水果超市系统matlab代码
2 部分代码
function varargout = rmbbb(varargin)% RMBBB MATLAB code for rmbbb.fig% RMBBB, by itself, creates a new RMBBB or raises the existing% singleton*.%% H = RMBBB returns the handle to a new RMBBB or the handle to% the existing singleton*.%% RMBBB('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in RMBBB.M with the given input arguments.%% RMBBB('Property','Value',...) creates a new RMBBB or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before rmbbb_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to rmbbb_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 rmbbb% Last Modified by GUIDE v2.5 11-Oct-2017 22:05:01% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @rmbbb_OpeningFcn, ... 'gui_OutputFcn', @rmbbb_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 rmbbb is made visible.function rmbbb_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 rmbbb (see VARARGIN)% Choose default command line output for rmbbbhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes rmbbb wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = rmbbb_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;function pushbutton1_Callback(hObject, eventdata, handles)% --- Executes on button press in pushbutton1.% 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 image %定义一个全局变量im[filename,pathname,filterindex]=uigetfile({'*.jpg';'*.png'},'选择图片')str=[pathname filename]; %合成路径+文件名image=imread(str); %读取图片axes(handles.axes1); %使用第一个axesimshow(image); %显示图片RGB = image; I = rgb2gray(RGB); threshold = graythresh(I); bw = im2bw(I,threshold); % remove all object containing fewer than 30 pixels bw = bwareaopen(bw,30); % fill a gap in the pen's cap se = strel('disk',2); bw = imclose(bw,se); % fill any holes, so that regionprops can be used to estimate % the area enclosed by each of the boundaries bw = imfill(bw,'holes'); ed=edge(bw); %%%%%以上是图像二值化 上面制作二值化图像 %下面计算圆度L = bwlabel(bw); L1 = bwlabel(ed); Ar=zeros(1,max(L(:))); Pr=zeros(1,max(L1(:))); for i=1:max(L(:)) Ar(i)=sum(bw(L==i)); [y,x]=find(L==i); x0=min(x(:)); x1=max(x(:)); y0=min(y(:)); y1=max(y(:)); Pr(i)=Ar(i)/((y1-y0)*(x1-x0)); end if max(Pr) >0.81 note=1else note=0endif note==1imager=image(:,:,1);imageg=image(:,:,2);r=sum(sum(imager));g=sum(sum(imageg));bizhi=r/g;if bizhi>1.15 money=100elseif bizhi<0.93 money=50elseif (bizhi>1.08)&(bizhi<1.15) money=20elseif (bizhi>1.0)&(bizhi<1.03) money=10elseif (bizhi>1.03)&(bizhi<1.08) money=5elseif (bizhi>0.93)&(bizhi<1.0) money=1endendif note==0 total= bwarea(bw)if total>12000 money=1elseif (total>10000)&(total<12000) money=0.5elseif (total>8700)&(total<10000) money=0.1else money=0endendglobal allmoney;set(handles.edit1,'string',money);allmoney=allmoney+money;set(handles.edit8,'string',allmoney);function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (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 edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (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');endallmoney=0;function edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (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 edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (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% --- 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)function edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (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 edit4 as text% str2double(get(hObject,'String')) returns contents of edit4 as a double% --- Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (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');endfunction edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (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 edit5 as text% str2double(get(hObject,'String')) returns contents of edit5 as a double% --- Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (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');endfunction edit6_Callback(hObject, eventdata, handles)% hObject handle to edit6 (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 edit6 as text% str2double(get(hObject,'String')) returns contents of edit6 as a double end end endendset(handles.edit4,'string',R);set(handles.edit5,'string',p);% 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)% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)m = str2num(get(handles.edit6,'string'));p = str2num(get(handles.edit5,'string'));global qq=m*p;set(handles.edit7,'string',q);% 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)function edit8_Callback(hObject, eventdata, handles)% hObject handle to edit8 (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 edit8 as text% str2double(get(hObject,'String')) returns contents of edit8 as a double% --- Executes during object creation, after setting all properties.function edit8_CreateFcn(hObject, eventdata, handles)% hObject handle to edit8 (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% --- Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)%pay= str2num(get(handles.edit7,'string'));global qpay=q;global allmoneyif (allmoney<pay) Button=questdlg('您支付的金额不足','提示','继续支付','取消支付','继续支付'); switch Button case '取消支付' helpdlg('交易失败','提示') allmoney=0; endelsecash=allmoney-pay;set(handles.edit3,'string',cash);helpdlg('欢迎下次光临','交易成功')allmoney=0;end% 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)% --- Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)im=imread('kongbai.jpg'); axes(handles.axes1); %使用第一个axes imshow(im); axes(handles.axes2); %使用第一个axes imshow(im); set(handles.edit1,'string',''); set(handles.edit3,'string',''); set(handles.edit4,'string',''); set(handles.edit5,'string',''); set(handles.edit6,'string',''); set(handles.edit7,'string',''); set(handles.edit8,'string',''); allmoney=0;% 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)
3 仿真结果

5 MATLAB代码与数据下载地址
见博客主页