function varargout = S111(varargin)
% S111 MATLAB code for S111.fig
% S111, by itself, creates a new S111 or raises the existing
% singleton*.
%
% H = S111 returns the handle to a new S111 or the handle to
% the existing singleton*.
%
% S111('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in S111.M with the given input arguments.
%
% S111('Property','Value',...) creates a new S111 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before S111_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to S111_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
%---------------------------------------------%
% %
% 工作室提供代做matlab仿真 %
% %
% 详情请访问:http://cn.mikecrm.com/DeOOXFc %
% %
%---------------------------------------------%
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @S111_OpeningFcn, ...
'gui_OutputFcn', @S111_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 S111 is made visible.
function S111_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 S111 (see VARARGIN)
% Choose default command line output for S111
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes S111 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = S111_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 xuanze.
function xuanze_Callback(hObject, eventdata, handles)
% hObject handle to xuanze (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';'*.tif';'*.png'},'select picture');%选择图片路径
str1=[pathname filename];%合成路径+文件名
cla reset;%清空axes界面
global I;
I=imread(str1);%读取图片
axes(handles.axes1);
imshow(I);
set(handles.tupian,'String',filename);
set(handles.zongshu,'String',0);
% --- Executes on button press in start.
function start_Callback(hObject, eventdata, handles)
% hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I;
thresh = 0.2;%二值化阈值设定
coin1 = im2bw(I,thresh);%二值化
coin2 = imfill(coin1,'holes');%该函数用于填充图像区域和"空洞"
[L Ne]=bwlabel(double(coin2));%bwlabel函数的作用是对矩阵中的连通区域赋以标号
prop=regionprops(L,'Area','Centroid');%用来度量图像区域属性的函数
total=0;
hold on
% Money count based on area of coin %阈值设定
i1=0;sum1=0; i2=0;sum2=0; i3=0;sum3=0;result1=0;result2=0;result3=0;
for n=1:size(prop,1); %For 1 to Total number of coins
cent=prop(n).Centroid;%质心
X=cent(1);Y=cent(2);%坐标
if prop(n).Area>11000
i1=i1+1;
sum1=sum1+prop(n).Area;
result1=sum1/i1;
text(X-25,Y+20,'1元','color','b')
text(X-100,Y-30,['(',num2str(X),',',num2str(Y),')'],'color','b')
total=total+10;
E(i1,1)=round(X);E(i1,2)=round(Y);
end
if prop(n).Area>7000&&prop(n).Area<11000
i2=i2+1;
sum2=sum2+prop(n).Area;
result2=sum2/i2;
text(X-10,Y-15,'5角','color','r')
text(X-100,Y+20,['(',num2str(X),',',num2str(Y),')'],'color','r')
total=total+5;
E(i2,3)=round(X);E(i2,4)=round(Y);
end
if prop(n).Area>500&&prop(n).Area<7000
i3=i3+1;
sum3=sum3+prop(n).Area;
result3=sum3/i3;
text(X-10,Y-10,'1角','color','y')
text(X-100,Y+10,['(',num2str(X),',',num2str(Y),')'],'color','y')
total=total+1;
E(i3,5)=round(X);E(i3,6)=round(Y);
end
end
%一元硬币直径25mm;10.25/49.6801=0.20632004(比例尺)
r1=sqrt(result1/pi);R1=r1*0.20632004;D1=2*R1;%测得1元硬币的直径
r2=sqrt(result2/pi);R2=r2*0.20632004;D2=2*R2;%测得5角硬币的直径
r3=sqrt(result3/pi);R3=r3*0.20632004;D3=2*R3;%测得1角硬币的直径
E(6,1)=i1;E(6,3)=i2;E(6,5)=i3;E(6,2)=D1;E(6,4)=D2;E(6,6)=D3;
set(handles.table,'Data',E(:,1:end));set(handles.zongshu,'String',total);
function zongshu_Callback(hObject, eventdata, handles)
% hObject handle to zongshu (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 zongshu as text
% str2double(get(hObject,'String')) returns contents of zongshu as a double
% --- Executes during object creation, after setting all properties.
function zongshu_CreateFcn(hObject, eventdata, handles)
% hObject handle to zongshu (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 tupian_Callback(hObject, eventdata, handles)
% hObject handle to tupian (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 tupian as text
% str2double(get(hObject,'String')) returns contents of tupian as a double
% --- Executes during object creation, after setting all properties.
function tupian_CreateFcn(hObject, eventdata, handles)
% hObject handle to tupian (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 during object creation, after setting all properties.
function table_CreateFcn(hObject, eventdata, handles)
% hObject handle to table (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called