function varargout = ZXH(varargin)
% ZXH MATLAB code for ZXH.fig
% ZXH, by itself, creates a new ZXH or raises the existing
% singleton*.
%
% H = ZXH returns the handle to a new ZXH or the handle to
% the existing singleton*.
%
% ZXH('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ZXH.M with the given input arguments.
%
% ZXH('Property','Value',...) creates a new ZXH or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ZXH_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ZXH_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 ZXH
% Last Modified by GUIDE v2.5 21-May-2020 10:41:25
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ZXH_OpeningFcn, ...
'gui_OutputFcn', @ZXH_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 ZXH is made visible.
function ZXH_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 ZXH (see VARARGIN)
% Choose default command line output for ZXH
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ZXH wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ZXH_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({'*.jpg';'*.bmp, *.jpg, *.tif';'*.bmp';'*.jpg';'*.tif';},'选择图像');
if isequal(filename,0)||isequal(pathname,0) %isequal函数判断若干个给定的数组容量(contents)是否是相等的
errordlg('您还没有选取图片!!','温馨提示');%如果没有输入,则创建错误对话框
return;
else
global I
image=[pathname,filename];%合成路径+文件名,image函数直接把矩阵中的数当做索引值,RGB1-64
I=imread(image);%读取图像
[x,y] = size(I);%将矩阵I的行数返回到第一个输出变量x,将矩阵的列数返回到第二个输出变量y,生成一个x行y列的矩阵,读取图片大小。
set(handles.axes1,'HandleVisibility','ON');%打开坐标,方便操作,设置图形对象属性,可从命令窗口和GUI访问。handlevisibility:用于设置控件的句柄可访问性。
axes(handles.axes1);%%使用图像,操作在坐标1
imshow(I);%在坐标axes1显示原图像
title('原始图像');
%人工阈值分割
global Y %全局变量Y
HSV = rgb2hsv(I);%HSV颜色模型转换。
S = HSV( :, :, 2 );%提取S分量。
[m,n]=size(S);
Y=S;
for i=1:m
for j=1:n
if(S(i,j)<0.1) %0.1是根据灰度直方图主观选取的数
Y(i,j)=0;
else
Y(i,j)=1;
end
end
end
set(handles.axes2,'HandleVisibility','ON');%打开坐标,方便操作
axes(handles.axes2);%%使用图像,操作在坐标2
imshow(Y);%在坐标axes2显示原图像
title('人工阈值进行分割');
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)
area(handles);%调用标记1获取函数,获取标记玉米种子的数目,并输出。
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 slider movement.
function slider1_Callback(hObject, eventdata, handles)%删除小面积滑杆
% hObject handle to slider1 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
area(handles);%调用标记1获取函数,根据设定的阈值,删除小面积物体后,再获取标记玉米种子的数目,并输出。
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)%裂纹检测按钮
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%定义全局变量
global I
global I6
global M
global N
I1=rgb2gray(I); %灰度图转换
[M,N]=size(I1); %获取图片尺寸
I2=double(I1); %精度转换
% 基本参数
Fd=0.8;
FD=-1*Fd;
% Fe=128;
Fe=128;
Xmax=255;
% 模糊特征平面
for i=1:M
for j=1:N
P(i,j)=(1+(Xmax-I2(i,j))/Fe)^FD;
end
end
% 模糊增强
times=1;
for k=1:times
for i=1:M
for j=1:N
if P(i,j) <= 0.5000
P1(i,j)=2*P(i,j)^2;
else
P1(i,j)=1-2*(1-P(i,j))^2;
end
end
end
P=P1;
end
% 反模糊化
for i=1:M
for j=1:N
I3(i,j)=Xmax-Fe*((1/P(i,j))^(1/Fd)-1);
end
end
I4=uint8(I3);
%浮雕化处理
[Height,Width] = size(I4);
I5 = zeros(Height,Width);
TH = 120;%阈值
%根据计算公式,重新给每个像素点赋值,得到浮雕图。
for i = 1:Height
for j=