Matlab显示图片的Edge


Matlab中显示Edge的函数

edge(Binary Image图片对象, edge类型[,  阈值 ])


比如 edge(img, 'sobel')

可选的edge有 'sobel',    'prewitt',   'prewitt',  'log',  'roberts',  'zerocross',  'canny'


function showEdge( imgPath , edgeType)


    %Show the original image and the edge result in the same window.


    clf;
    close all;

    % Read Image
    img = imread(imgPath);

    % convert to binary image
    bi = im2bw(img);
    result1=edge(bi, edgeType);

    % Show original Image and Edge Image
    subplot(1, 2, 1);
    imshow(img);
    subplot(1, 2, 2);
    imshow(result1);
    
end



比如:

showEdge('a.jpg', 'log');


### MATLAB `edge` 函数使用方法 #### 功能描述 `edge` 函数用于边界检测,能够识别灰度图像或多光谱图像中的边缘。该函数提供了多种算法来实现这一目标,包括 Sobel 方法、Prewitt 方法、Roberts 方法以及 Laplacian of Gaussian (LoG) 方法等[^1]。 #### 基本语法 最简单的调用方式如下所示: ```matlab BW = edge(I, method); ``` 其中 `I` 表示输入的二维灰度图像矩阵;`method` 参数指定了使用的具体边缘检测算法名称字符串形式指定,比如 `'sobel'`, `'prewitt'`, 或者 `'log'` 等。 对于更复杂的场景可以设置阈值参数以控制灵敏度: ```matlab BW = edge(I,'canny',[low_threshold high_threshold]); ``` 这里定义了一个双阈值 Canny 边缘探测器实例,通过调整高低两个不同的门限值来优化最终效果。 另外还可以利用额外选项来自定义为模式,例如设定感兴趣区域(Region Of Interest): ```matlab BW = edge(I,...,'ROI',rect); ``` 这里的 `rect=[xmin ymin width height]` 定义了一个矩形范围内的处理区间[^3]。 #### 实际应用案例 下面给出一段完整的代码片段展示如何运用上述提到的功能特性来进基本操作: ```matlab % 加载测试图片并转换成灰度图 img = imread('coins.png'); gray_img = rgb2gray(img); % 应用不同类型的边缘检测算子 bw_sobel = edge(gray_img,'sobel'); % sobel operator bw_prewitt = edge(gray_img,'prewitt'); % prewitt operator bw_log = edge(gray_img,'log'); % laplacian-of-gaussian filter % 显示结果对比 figure; subplot(2,2,1); imshow(img); title('Original Image'); subplot(2,2,2); imshow(bw_sobel); title('Sobel Edges'); subplot(2,2,3); imshow(bw_prewitt); title('Prewitt Edges'); subplot(2,2,4); imshow(bw_log); title('Log Edges'); ``` 这段程序读取了一张名为 "coins.png" 的彩色图像文件,并将其转化为单通道强度信号表示形式以便后续分析处理。接着分别采用了三种常见的边缘提取技术对其进变换得到二值化后的轮廓线条映射关系图样最后组合排列在同一窗口内方便直观比较观察各个方案之间的差异特点。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值