【数字图像处理+MATLAB】通过 Roberts, Prewitt, Sobel, LoG 等算子实现图像边缘检测:使用 edge 函数

引言

边缘检测是图像处理中的一种技术,用于识别图像中的物体边界。边缘是图像亮度函数快速变化的地方,通常对应于物体或物体部分的边界。边缘检测的目标是显著减少图像中的数据量,同时保留有用的结构信息。常用的边缘检测算法包括Sobel、Prewitt、Roberts、Canny等。


函数详解

edge

edge是MATLAB中的一个函数,用于检测图像中的边缘。

基本语法:

matlab 复制代码
BW = edge(I)
BW = edge(I,method)
BW = edge(I,method,threshold)
BW = edge(I,method,threshold,direction)
[BW,threshOut] = edge(___)

参数详解:

  • I:输入图像,应为二维灰度图像。
  • method:边缘检测方法,可选值包括 'Sobel'(默认值)、'Prewitt''Roberts''Log''Canny'等。
  • threshold:阈值,用于确定边缘的强度。如果未指定,edge函数会自动计算阈值。
  • direction:方向,仅在method'Sobel''Prewitt''Roberts'时使用。可选值为'horizontal''vertical'

返回值详解:

  • BW:输出图像,是一个二值图像,其中边缘像素为1,非边缘像素为0。
  • threshOut:实际使用的阈值。如果输入参数中未指定阈值,edge函数会自动计算一个阈值,并通过threshOut返回。

应用案例

matlab 复制代码
% 读取图像
img1 = imread("Fig1016(a)(building_original).tif");

% 创建一个新的图形窗口
figure;

% 显示原始图像
subplot(3, 2, 1);
imshow(img1);
title("Original image");

% 使用Roberts方法检测边缘
roberts = edge(img1, 'roberts');
subplot(3, 2, 3);
imshow(roberts);
title("Roberts");

% 使用Prewitt方法检测边缘
prewitt = edge(img1, 'prewitt');
subplot(3, 2, 4);
imshow(prewitt);
title("Prewitt");

% 使用Sobel方法检测边缘
sobel = edge(img1, 'sobel');
subplot(3, 2, 5);
imshow(sobel);
title("Sobel")

% 使用Log方法检测边缘
log = edge(img1, 'log');
subplot(3, 2, 6);
imshow(log);
title("Log")
相关推荐
Sylvia-girl4 小时前
Java——抽象类
java·开发语言
Yana.nice6 小时前
Bash函数详解
开发语言·chrome·bash
tomorrow.hello8 小时前
Java并发测试工具
java·开发语言·测试工具
晓13138 小时前
JavaScript加强篇——第四章 日期对象与DOM节点(基础)
开发语言·前端·javascript
老胖闲聊8 小时前
Python I/O 库【输入输出】全面详解
开发语言·python
她说人狗殊途10 小时前
java.net.InetAddress
java·开发语言
天使day10 小时前
Cursor的使用
java·开发语言·ai
Dxy123931021610 小时前
Python ExcelWriter详解:从基础到高级的完整指南
开发语言·python
源代码•宸12 小时前
C++高频知识点(十三)
开发语言·c++·经验分享·面经
wa的一声哭了12 小时前
python基础知识pip配置pip.conf文件
java·服务器·开发语言·python·pip·risc-v·os