clear;
clc;
h0=figure('toolbar','none','menubar','none',...
'position',[198 56 458 400],...
'name','基于Otsu准则的运动目标检测与识别');
h1=axes('parent',h0,...
'tag','h1',...
'position',[0.15 0.4 0.7 0.5],...
'visible','off');
u1=uimenu('parent',h0,...
'tag','u1',...
'label','文件',...
'backgroundcolor',[0.75 0.75 0.75]);
u11=uimenu('parent',u1,...
'tag','u12',...
'label','打开',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'[fname,pname,filterindex] = uigetfile({''*.bmp'';''*.jpg'';''*.tif''},''打开图片'');,',...
'I=imread([pname,fname]);,',...
'imshow(I);title(''原始图像'');']);
u12=uimenu('parent',u1,...
'tag','u13',...
'label','保存',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'[fname,pname,filterindex] = uiputfile(''*.bmp'',''保存图片'');,',...
'mysavename=strcat(pname,fname,''.bmp'');,',...
'imwrite(savepic,mysavename);']);
u13=uimenu('parent',u1,...
'tag','u14',...
'label','退出',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback','close');
u2=uimenu('parent',h0,...
'tag','u2',...
'label','图像预处理',...
'backgroundcolor',[0.75 0.75 0.75]);
u21=uimenu('parent',u2,...
'tag','u21',...
'label','直方图',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback','figure,imhist(I)');
u22=uimenu('parent',u2,...
'tag','u22',...
'label','平滑处理(去噪声)',...
'backgroundcolor',[0.75 0.75 0.75]);
u221=uimenu('parent',u22,...
'tag','u221',...
'label','自适应滤波',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'cla,',...
'pic=wiener2(I,[5 5]);,'...
'savepic=pic;,'...
'imshow(pic);title(''自适应滤波后的图像'');']);
u222=uimenu('parent',u22,...
'tag','u222',...
'label','中值滤波',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'cla,',...
'pic=medfilt2(I,[3 3]);,'...
'savepic=pic;,'...
'imshow(pic);title(''中值滤波后的图像'');']);
u3=uimenu('parent',h0,...
'tag','u3',...
'label','图像分割',...
'backgroundcolor',[0.75 0.75 0.75]);
u31=uimenu('parent',u3,...
'tag','u31',...
'label','OTSU',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'cla,',...
'th=Ostu(pic);,'...
'PIC1=thresh(I,th);,'...
'savepic=PIC1;,'...
'imshow(PIC1);title(''OTSU阈值分割后的二值图像'');']);
u32=uimenu('parent',u3,...
'tag','u32',...
'label','双阈值OTSU',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'cla,',...
'PIC1=doubOTSU(pic);,'...
'imshow(PIC1);title(''OTSU双阈值分割后的二值图像'');']);
u33=uimenu('parent',u3,...
'tag','u33',...
'label','去背景',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'cla,',...
'bgim=imread(''soursepic\bg.bmp'');,'...
'picture = removebg(PIC1,bgim);,',...
'savepic=picture;,'...
'imshow(picture);title(''去背景后的二值图像'');']);
u4=uimenu('parent',h0,...
'tag','u4',...
'label','形态学处理',...
'backgroundcolor',[0.75 0.75 0.75]);
u41=uimenu('parent',u4,...
'tag','u41',...
'label','开运算',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'cla,',...
'se=strel(''disk'',1);,',...
'temp=imopen(savepic,se);,'...
'savepic=temp;,'...
'imshow(temp);title(''形态学开运算结果'');']);
u42=uimenu('parent',u4,...
'tag','u42',...
'label','闭运算',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'cla,',...
'se=strel(''disk'',1);,',...
'temp=imclose(savepic,se);,'...
'savepic=temp;,'...
'imshow(temp);title(''形态学闭运算结果'');']);
u5=uimenu('parent',h0,...
'tag','u5',...
'label','检测与识别',...
'backgroundcolor',[0.75 0.75 0.75]);
u51=uimenu('parent',u5,...
'tag','u51',...
'label','目标识别',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback','objgz(temp);');
u52=uimenu('parent',u5,...
'tag','u52',...
'label','目标跟踪显示',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'cla,',...
'mov=aviread(''final.avi'');,'...
'movie(mov);title(''视频序列'');']);