function varargout = orange_shibie(varargin)
% ORANGE_SHIBIE MATLAB code for orange_shibie.fig
% ORANGE_SHIBIE, by itself, creates a new ORANGE_SHIBIE or raises the existing
% singleton*.
%
% H = ORANGE_SHIBIE returns the handle to a new ORANGE_SHIBIE or the handle to
% the existing singleton*.
%
% ORANGE_SHIBIE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ORANGE_SHIBIE.M with the given input arguments.
%
% ORANGE_SHIBIE('Property','Value',...) creates a new ORANGE_SHIBIE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before orange_shibie_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to orange_shibie_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 orange_shibie
% Last Modified by GUIDE v2.5 03-Dec-2019 21:58:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @orange_shibie_OpeningFcn, ...
'gui_OutputFcn', @orange_shibie_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 orange_shibie is made visible.
function orange_shibie_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 orange_shibie (see VARARGIN)
% Choose default command line output for orange_shibie
handles.output = hObject;
global im;
im=imread('e.jpg');
axes(handles.axes3);
imshow(im);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes orange_shibie wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = orange_shibie_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 axes2_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
axis off;
% Hint: place code in OpeningFcn to populate axes2
% --- 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)
global im;
im_double = im2double(im);
hsize = 9;
sigma = 3;
h = fspecial('gaussian', hsize, sigma);
% 使用高斯滤镜进行局部变化
im_blur = imfilter(im_double, h, 'same', 'repl');
% ntsc空间
im_yiq = rgb2ntsc(im_blur);
im_i = im_yiq(:,:,2);
% HSV空间进行颜色初筛
im_hsv = rgb2hsv(im);
im_h=im_hsv(:,:,1);
im_v=im_hsv(:,:,3);
im_qa = zeros(size(im_h));
for x = 1 : size(im_qa,1)
for y = 1 : size(im_qa,2)
if im_h(x, y) >= 15/360 && im_h(x, y) <= 40/360 && im_v(x, y)>=70/100
im_qa(x, y) = 1;
end
if im_h(x, y) >= 40/360 && im_h(x, y) <= 46/360 && im_v(x, y)>=95/100
im_qa(x, y) = 1;
end
if im_h(x, y) >= 10/360 && im_h(x, y) <= 20/360 && im_v(x, y)>=40/100 && im_v(x, y)<=70/100
im_qa(x, y) = 1;
end
if im_h(x, y) >= 41/360 && im_h(x, y) <= 57/360 && im_v(x, y)>=93/100;
im_qa(x, y) = 1;
end
end
end
im_qa = imbinarize(im_qa);
el = [1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1];
im_qa=imerode(im_qa, el);
im_qa=imerode(im_qa, el);
for i=1:12
im_qa = imdilate(im_qa, el);
end
% 分割亮色
im_quant1 = zeros(size(im_i));
for x = 1 : size(im_i, 1)
for y = 1 : size(im_i, 2)
if im_i(x, y) >= 0.12 && im_i(x, y) <= 0.15
im_quant1(x, y) = 0.0;
end
if im_i(x, y) >= 0.151 && im_i(x, y) <= 0.225
im_quant1(x, y) = 0.1;
end
if im_i(x, y) >= 0.25 && im_i(x, y) <= 1
im_quant1(x, y) = 0.7;
end
end
end
% 转换为二值图像,保留0.7的部分,并且膨胀4次
im_quant = imbinarize(im_quant1);
el = [1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1];
im_quant = imdilate(im_quant, el);
im_quant = imdilate(im_quant, el);
im_quant = imdilate(im_quant, el);
im_quant = imdilate(im_quant, el);
im_quant=logical(im_quant.*im_qa);
axes(handles.axes2);
imshow(im);
%设置橙子半径范围
bt_r_range_2 = [61 120];
bt_r_range_3 = [121 220];
% 画圆
[circles, radii1] = imfindcircles(im_quant, bt_r_range_2, 'ObjectPolarity', 'bright', 'sensitivity', 0.95);
viscircles(circles, radii1, 'Edgecolor', 'g');
[circles, radii2] = imfindcircles(im_quant, bt_r_range_3, 'ObjectPolarity', 'bright', 'sensitivity', 0.95);
viscircles(circles, radii2, 'Edgecolor', 'b');
num=size(radii1,1)+size(radii2,1);
% 计数
set(handles.text3,'string',num);
% --- 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)
global im
global str_name
im=imread(str_name);
axes(handles.axes3);
imshow(im);
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');
end
% --- 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)
global str_name;
hhh=get(handles.popu