function picprocess()
hFigure = figure('position',[0 0 700 500],'name','织物缺陷检测软件','visible','off');%创建一个界面
movegui(hFigure,'center');%显示在中间
delete(findall(hFigure,'type','uimenu'));%删除菜单栏
hToolBar = findall(hFigure,'type','uitoolbar');%找出工具栏
set(allchild(hToolBar),'Visible','off');%隐藏工具栏所有的子对象
hTools = findall(hToolBar,'Tooltip','Zoom In','-or','Tooltip','Zoom Out','-or','Tooltip','Pan');%找出你要的四个工具,另存为hTools
set(hTools,'Visible','on','Separator','off');%显示这三个工具
hAxes=axes('visible','off','Units','normalized','position',[0 0 1 1]);%创建坐标轴,用于显示背景
cData = imread('timg.jpg');
image(cData);
axis off;%输入背景图并且去掉坐标轴
hMenu=uimenu(hFigure);
xingqi={'日','一','二','三','四','五','六'};
set(hMenu,'Label',[datestr(clock) '星期' xingqi{weekday(now)}]);
drawnow;%显示时间
set(0,'Defaultuicontrolfontsize',12);
uicontrol('string','导入图片','position',[60 150 90 30],'Callback',@openPic);%导入图像按键
uicontrol('string','保存图片','position',[180 150 90 30],'Callback',@savePic);%导入图像按键
uicontrol('string','退 出','position',[300 150 90 30],'Callback','close(gcbf)');%关闭软件
uicontrol('string','检测织物','position',[420 150 90 30],'Callback',@testPic);%检测图像
set(hFigure,'Visible','on');%界面显示
end
function openPic(~,~)
hAxes1=axes('Units','normalized','position',[0.05 0.45 0.45 0.45]);
title('织物图像','Color','g');
axis off;%显示织物图像
[fName,pName,index]=uigetfile({'*.jpg';'*.png';'*.bmp'},'选择要打开的图片文件');%获取文件名称路径,类型
if index
str=[pName fName];
cla;%清除
imshow(str);
end
hAxes2=axes('Units','normalized','position',[0.55 0.45 0.45 0.45]);
title('织物图像','Color','g');
axis off;%显示处理图像
if index
global str
str=[pName fName];
I=imread(str);
global x;%声明全局变量
x=im2bw(I);
cla;%清除
imshow(x);
end
end
function savePic(~,~)
global x;%局部作用域里的局部变量会把全局变量覆盖掉,所以要
imwrite(x,'G:\Graduation design\matlab programming\保存图片\1.jpg');
end
function testPic(~,~)
%h=warndlg('aaa','警告!');
% helpdlg;
% hDialog=findall(0,'tag','Msgbox_Error Dialog');
% btn_ok=findall(hDialog,'style','pushbutton');
% set(btn_ok,'String','确定');
title='结果';
global str;
a='该织物的状态是:';
indfir=max(strfind(str,'\'));
indlas=strfind(str,'.');
b=str(indfir+1:indlas-3); %截取了最后一个‘\’和‘.’之间的字符串。
message=strcat(a,b);
h=msgbox(message,title,'help');
end