基于MATLAB边缘检测博文

界面GUI的设计

整个设计的人机交互界面GUI需要人性化,并且突出边缘检测前后图像的对比,可以在界面灵活地选取不同算法。设计草图如图4-1所示。

GUI界面的制作

该人机交互界面GUI,具有界面友好,容易操作等特征。首先打开matalb软件,在命令窗口command window输入guide,并且敲击回车键,进入matlab GUI快速打开方式窗口。出现如下图:

点击OK确定,进入GUI编辑界面窗口。

在设计上,拉动2个大小完全相同的Axes方框,用于分别放置边缘检测图像前后对比图像,以达到直观对比效果。界面上制作一个菜单的打开按钮,用于打开选择所要边缘检测处理的图像,句柄内填充以下代码以实现功能。

filename, pathname\] = uigetfile({'\*.bmp';'\*.jpg';'\*.jpeg'},'Pick an image-file'); if isequal(filename,0) \| isequal(pathname,0) disp('User pressed cancel'); else disp(\['User selected ', fullfile(pathname, filename)\]) end x=imread(filename); \[width,height,Cnums\]=size(x); a=log2(width); b=log2(height); axes(handles.axes2); imshow(zeros(\[256,256\])); if (Cnums\~=1) if (width\>256)\|(height\>256) W=max(width,height); else W=256; end for m=1:W for n=1:W if (m\<=width)\&(n\<=height) extendx(m,n,:)=x(m,n,:); else extendx(m,n,:)=realmax; end end end axes(handles.axes1); imshow(extendx); handles.rgb=x; msgbox('Please transform it to a gray image or it can not be processed correctly','fileopening','warning'); elseif (width\>256)\|(height\>256) W=max(width,height); for m=1:W for n=1:W if (m\<=width)\&(n\<=height) extendx(m,n)=x(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes1); imshow(extendx); msgbox('The height or width is larger than 256 or they are both larger than 256!','fileopening','warning') elseif (width\<256)\|(height\<256) for m=1:256 for n=1:256 if (m\<=width)\&(n\<=height) extendx(m,n)=x(m,n); else extendx(m,n)=realmax; end end end axes(handles.axes1); imshow(extendx); msgbox('The height or width is less than 256 or they are both less than 256!','fileopening','warning'); else axes(handles.axes1); imshow(x); end handles.imdata=x; handles.reload=handles.imdata; guidata(hObject, handles); 打开的实现功能如下: ![](https://i-blog.csdnimg.cn/direct/fe8aa2878bd5406b8eb337716d5da9d4.png) 在算法选择上,也是利用菜单的下拉按钮pushbutton的形式实现,如下图: ![](https://i-blog.csdnimg.cn/direct/216e7dc1a8844b80ac14211ca3552f02.png) 图4-2 算法选择菜单 另外,为了从本质上解释图像边缘检测达到效果的原因,特别在GUI界面上设计了2个大小完全一样的axes,用于呈现边缘检测前后两图像的灰度直方图。通过bitton按钮以实现显示直方图。实现的代码如下: if isequal(handles.Img1, 0) msgbox('请载入原图像!', '提示信息'); return; end if isequal(handles.Img2, 0) msgbox('请进行边缘检测处理!', '提示信息'); return; end #### 运行效果示意图 #### ![](https://i-blog.csdnimg.cn/direct/422e27743bb942fbbec8abc9be7a2e8a.png) ![](https://i-blog.csdnimg.cn/direct/2d62e45b1f35479bb038a080a2698c46.png) ![](https://i-blog.csdnimg.cn/direct/0766e71305c24692a1478c277bb198b9.png)

相关推荐
麦麦鸡腿堡35 分钟前
Java的动态绑定机制(重要)
java·开发语言·算法
时间之里36 分钟前
【c++】:Lambda 表达式介绍和使用
开发语言·c++
zy_destiny42 分钟前
【工业场景】用YOLOv8实现抽烟识别
人工智能·python·算法·yolo·机器学习·计算机视觉·目标跟踪
Tiger_shl1 小时前
C# 预处理指令 (# 指令) 详解
开发语言·c#
坚持编程的菜鸟1 小时前
LeetCode每日一题——螺旋矩阵
c语言·算法·leetcode·矩阵
汉克老师1 小时前
GESP2025年9月认证C++四级( 第三部分编程题(1)排兵布阵)
c++·算法·gesp4级·gesp四级
(●—●)橘子……1 小时前
记力扣2009:使数组连续的最少操作数 练习理解
数据结构·python·算法·leetcode
GalaxyPokemon1 小时前
LeetCode - 1171.
算法·leetcode·链表
@Kerry~1 小时前
phpstudy .htaccess 文件内容
java·开发语言·前端
CRMEB系统商城1 小时前
CRMEB多商户系统(PHP)v3.3正式发布,同城配送上线[特殊字符]
java·开发语言·小程序·php