function net_test
%====================================
% Define the Figure Window without MenuBar
hFigure=figure('Name','Image Processing',...
'MenuBar','none',...
'NumberTitle','off',...
'Visible','on');
%====================================
% Define a toolbar to open the file
hToolbar = uitoolbar(hFigure);
open=imread('open.jpg');
hOpen = uipushtool(hToolbar,'CData',open,...
'ClickedCallback',@open_file,...
'Separator','on',...
'TooltipString','Open File');
%====================================
% Custom a menu with parent Named File
hMenu1=uimenu('Parent',hFigure,...
'Separator','on',...
'Label','File',...
'Callback',@open_file...
);
%====================================
% Custom a menu with parent Named Add
hMenu2=uimenu('Parent',hFigure,...
'Separator','on',...
'Label','Add'...
);
%====================================
% Define the children menu of Add
hMenu2sub1=uimenu(hMenu2,...
'Label','Add New Class',...
'Callback',@add_class...
);
hMenu2sub2=uimenu(hMenu2,...
'Label','Add Image',...
'Callback',@add_image...
);
%====================================
% Custom a menu with parent Named Remove
hMenu3=uimenu('Parent',hFigure,...
'Separator','on',...
'Label','Remove'...
);
%====================================
% Define the children menu of Add
hMenu3sub1=uimenu(hMenu3,...
'Label','Remove New Class',...
'Callback',@remove_class...
);
hMenu3sub2=uimenu(hMenu3,...
'Label','Remove Image',...
'Callback',@Remove_image...
);
%====================================
% Set the attribute of pushbutton 'Image Display'
display=uicontrol( ...
'Parent', hFigure, ...
'BusyAction','Queue','Interruptible','off',...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[0.15 0.2 0.15 0.08], ...
'String','Image Display', ...
'Enable', 'on', ...
'Callback',@open_file);
%====================================
% The Images Label
color=get(hFigure,'Color');
hStatic11 = uicontrol( ...
'Parent', hFigure, ...
'BusyAction','Queue','Interruptible','off',...
'Style','text', ...
'Units','normalized', ...
'Position',[0.48 0.63 0.18 0.1], ...
'Horiz','center', ...
'Background',color,...
'Foreground','red', ...
'String','The Display Texture Value of The Image');
%====================================
% The Images Label
hStatic = uicontrol( ...
'Parent', hFigure, ...
'BusyAction','Queue','Interruptible','off',...
'Style','text', ...
'Units','normalized', ...
'Position',[0.46 0.35 0.2 0.28], ...
'Horiz','center', ...
'Background',[0.8 0.8 1],...
'Foreground','blue', ...
'String','Texture');
%====================================
% The Images Label
hStatic2 = uicontrol( ...
'Parent', hFigure, ...
'BusyAction','Queue','Interruptible','off',...
'Style','text', ...
'Units','normalized', ...
'Position',[0.75 0.4 0.2 0.15], ...
'Horiz','center', ...
'Background',[0.8 0.8 1],...
'Foreground','blue', ...
'String','belongs to ');
%====================================
% The Images Label
hStatic0= uicontrol( ...
'Parent', hFigure, ...
'BusyAction','Queue','Interruptible','off',...
'Style','text', ...
'Units','normalized', ...
'Position',[0.75 0.55 0.2 0.08], ...
'Horiz','center', ...
'Background',color,...
'Foreground','red', ...
'String','The Test Value');
%====================================
% Set the attribute of pushbutton 'Texture Matrix'
Texture=uicontrol( ...
'Parent', hFigure, ...
'BusyAction','Queue','Interruptible','off',...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[0.5 0.2 0.15 0.08], ...
'String','Get Texture', ...
'Enable', 'on', ...
'Callback',@Texture);
%====================================
% Set the attribute of pushbutton 'Test Net'
Test_net=uicontrol( ...
'Parent', hFigure, ...
'BusyAction','Queue','Interruptible','off',...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[0.79 0.2 0.15 0.08], ...
'String','Test Net', ...
'Enable', 'on', ...
'Callback',@test_net);
%====================================
% Define a Axes in the figure above to place the Original Image
hAxes1=axes('Parent',hFigure,...
'Position',[0.06 0.35 0.3 0.4],...
'Visible','on');
image=imread('flower1.jpg');
image_show=imresize(image,[256 256]);
axes(hAxes1);
imshow(image_show);title('Original Image');
%====================================
% Create a new Network
% t_t=[0.0175 0.0213 0.0228 0.0238 0.0410 0.0484 0.0289 0.0227
% 0.0017 0.0020 0.0015 0.0021 0.0085 0.0101 0.0029 0.0022
% 4.3455 4.2723 4.3962 4.0865 3.5747 3.3868 3.8690 4.1214
% 0.1049 0.1026 0.0752 0.0908 0.1742 0.1780 0.1071 0.1018
% 2.6402 2.8811 5.0640 2.6620 0.8734 0.7155 1.7195 2.3772
% 0.6435 0.7644 1.0763 0.6069 0.2560 0.2192 0.3889 0.5299
% 0.0702 0.0570 0.0307 0.1028 0.1328 0.1571 0.1315 0.1148
% 0.0022 0.0016 0.0006 0.0048 0.0027 0.0030 0.0040 0.0050];
%
% T=[1 1 1 1 0 0 0 0
% 0 0 0 0 1 1 0 0
% 0 0 0 0 0 0 1 1];
%====================================
% Set the handles of figure1 and Save them
handles.hFigure=hFigure;
handles.hOpen=hOpen;
handles.hStatic=hStatic;
handles.hStatic2=hStatic2;
handles.hMenu1=hMenu1;
handles.display=display;
handles.axes1=hAxes1;
handles.image=image;
handles.flag=0;
set(hFigure, 'UserData',handles);
set(hFigure, 'HandleVisibility','Callback');
%====================================
% Sub_Functions Definition
% Sub_Function Implemention of open_file
function open_file(cbo,eventdata)
handles=get(gcbf,'UserData');
[FileName,PathName,FilterIndex]=uigetfile(...
{'*.jpg','JPG(*.jpg)';...
'*.bmp','BMP(*.bmp)';...
'*.tif','TIF(*.tif)';...
'*.png','PNG(*.png)';},...
'Select Image');
if PathName==0
return
end
path=[PathName FileName];
image=imread(path);
image_show=imresize(image,[256 256]);
handles.image=image;
set(gcbf, 'UserData',handles);
axes(handles.axes1);
imshow(image_show);
title('Original Image');
return
%====================================
% Sub_Function Implemention of Texture
function Texture(cbo,eventdata)
handles=get(gcbf,'UserData');
Image=handles.image;
[M N O]=size(Image);
%--------------------------------------------------------------------------
%1.将各颜色分量转化为灰度
%--------------------------------------------------------------------------
Gray = double(0.3*Image(:,:,1)+0.59*Image(:,:,2)+0.11*Image(:,:,3));
%--------------------------------------------------------------------------
%2.为了减少计算量,对原始图像灰度级压缩,将Gray量化成16级
%--------------------------------------------------------------------------
for i = 1:M
for j = 1:N
for n = 1:256/16
if (n-1)*16<=Gray(i,j)&Gray(i,j)<=(n-1)*16+15
Gray(i,j) = n-1;
end
end
end
end
%--------------------------------------------------------------------------
%3.计算四个共生矩阵P,取距离为1,角度分别为0,45,90,135
%--------------------------------------------------------------------------
P = zeros(16,16,4);
for m = 1:16
for n = 1:16
for i = 1:M
for j = 1:N
if j<N&Gray(i,j)==m-1&Gray(i,j+1)==n-1
P(m,n,1) = P(m,n,1)+1;
P(n,m,1) = P(m,n,1);
end
if i>1&j<N&Gray(i,j)