首页 > 其他分享 >Matlab实现:图像边缘提取

Matlab实现:图像边缘提取

时间:2022-10-31 15:35:25浏览次数:96  
标签:subplot 提取 图像 title imshow 边缘 edge Matlab 算子

1、 边缘提取算法

方法一:一阶微分算子

  • Sobel算子

clip_image001

Sobel算子检测方法对灰度渐变和噪声较多的图像处理效果较好,Sobel算子对边缘定位不是很准确,图像的边缘不止一个像素。

clip_image003

clip_image005

  • Roberts算子

clip_image006

Roberts算子检测方法对具有陡峭的低噪声的图像处理效果较好,但是利用roberts算子提取边缘的结果是边缘比较粗,因此边缘的定位不是很准确。

clip_image008

clip_image009

  • Prewitt算子

clip_image010

Prewitt算子检测方法对灰度渐变和噪声较多的图像处理效果较好。但边缘较宽,而且间断点多。

clip_image012

clip_image014

  • Canny算子

Canny算子是目前边缘检测最常用的算法,效果也是最理想的。

Canny边缘检测算法不是简单的模板卷积而已,通过梯度方向和双阈值法来检测边缘点,具体算法可以参考:http://www.cnblogs.com/AndyJee/p/3734805.html

Canny方法不容易受噪声干扰,能够检测到真正的弱边缘。优点在于,使用两种不同的阈值分别检测强边缘和弱边缘,并且当弱边缘和强边缘相连时,才将弱边缘包含在输出图像中。

clip_image016

clip_image018

方法二:二阶微分算子

  • Laplacian算子

clip_image019 clip_image020

Laplacian算子法对噪声比较敏感,所以很少用该算子检测边缘,而是用来判断边缘像素视为与图像的明区还是暗区。

clip_image022

clip_image024

2、 实验结果分析

一、边缘提取:

clip_image026

  • Sobel算子检测方法对灰度渐变和噪声较多的图像处理效果较好,sobel算子对边缘定位不是很准确,图像的边缘不止一个像素;
  • Roberts算子检测方法对具有陡峭的低噪声的图像处理效果较好,但是利用roberts算子提取边缘的结果是边缘比较粗,因此边缘的定位不是很准确;
  • Prewitt算子检测方法对灰度渐变和噪声较多的图像处理效果较好。但边缘较宽,而且间断点多;
  • Laplacian算子法对噪声比较敏感,所以很少用该算子检测边缘,而是用来判断边缘像素视为与图像的明区还是暗区;
  • Canny方法不容易受噪声干扰,能够检测到真正的弱边缘。优点在于,使用两种不同的阈值分别检测强边缘和弱边缘,并且当弱边缘和强边缘相连时,才将弱边缘包含在输出图像中。

二、边缘复合增强

clip_image028

  • Sobel、Robert、Prewitt算子的增强效果并不是很明显,尤其是Robert算子,因为它提取的边缘点过于稀疏和离散;
  • Laplacian算子和canny算子的增强效果都比较理想, 将边缘叠加上去后,整个手的轮廓和边缘都很清晰,直观上看,canny算子实现的效果比Laplacian算子好,最明显的地方就是手指尖的边缘。

3、程序实现

下面的程序就实现上面效果的完整Matlab代码:

复制代码
clear;clc;
I=imread('x1.tif');
% I=rgb2gray(I);
% gray transform

J=imadjust(I,[0.1 0.9],[0 1],1);

% Edge detection
% Sobel
BW1=edge(I,'sobel');
sobelBW1=im2uint8(BW1)+J;
figure;
%imshow(BW1);
subplot(1,2,1);
imshow(J);
title('original image');
subplot(1,2,2);
imshow(sobelBW1);
title('Sobel augmented image');
% Roberts
BW2=edge(I,'roberts');
robertBW2=im2uint8(BW2)+J;
figure;
%imshow(BW2);
subplot(1,2,1);
imshow(J);
title('original image');
subplot(1,2,2);
imshow(robertBW2);
title('robert augmented image');
% prewitt
BW3=edge(I,'prewitt');
prewittBW3=im2uint8(BW3)+J;
figure;
%imshow(BW3);
subplot(1,2,1);
imshow(J);
title('original image');
subplot(1,2,2);
imshow(prewittBW3);
title('Prewitt augmented image');
% log
BW4=edge(I,'log');
logBW4=im2uint8(BW4)+J;
figure;
%imshow(BW4);
subplot(1,2,1);
imshow(J);
title('original image');
subplot(1,2,2);
imshow(logBW4);
title('Laplacian augmented image');
% canny
BW5=edge(I,'canny');
cannyBW5=im2uint8(BW5)+J;
figure;
%imshow(BW5);
subplot(1,2,1);
imshow(J);
title('original image');
subplot(1,2,2);
imshow(cannyBW5);
title('Canny augmented image');
% gaussian & canny
% h=fspecial('gaussian',5); 
% fI=imfilter(I,h,'replicate');
% BW6=edge(fI,'canny');
% figure;
% imshow(BW6);

figure;
subplot(2,3,1), imshow(BW1); 
title('sobel edge detect'); 
subplot(2,3,2), imshow(BW2); 
title('roberts edge detect'); 
subplot(2,3,3), imshow(BW3); 
title('prewitt edge detect'); 
subplot(2,3,4), imshow(BW4); 
title('log edge detect'); 
subplot(2,3,5), imshow(BW5); 
title('canny edge detect'); 
% subplot(2,3,6), imshow(BW6); 
% title('gasussian&canny edge detect');

figure;
subplot(2,3,1), imshow(sobelBW1); 
title('sobel edge detect'); 
subplot(2,3,2), imshow(robertBW2); 
title('roberts edge detect'); 
subplot(2,3,3), imshow(prewittBW3); 
title('prewitt edge detect'); 
subplot(2,3,4), imshow(logBW4); 
title('laplacian edge detect'); 
subplot(2,3,5), imshow(cannyBW5); 
title('canny edge detect');
复制代码

下面的Matlab程序是精简的边缘提取实现:

复制代码
clear;clc;

I=imread('lena.bmp');
I=rgb2gray(I);
imshow(I,[]);
title('Original Image');

sobelBW=edge(I,'sobel');
figure;
imshow(sobelBW);
title('Sobel Edge');

robertsBW=edge(I,'roberts');
figure;
imshow(robertsBW);
title('Roberts Edge');

prewittBW=edge(I,'prewitt');
figure;
imshow(prewittBW);
title('Prewitt Edge');

logBW=edge(I,'log');
figure;
imshow(logBW);
title('Laplasian of Gaussian Edge');

cannyBW=edge(I,'canny');
figure;
imshow(cannyBW);
title('Canny Edge');
复制代码


本文出自https://www.cnblogs.com/AndyJee/p/3737325.html

招募大量matlab技术人员,有大量matlab需求订单,均为个人短期可以完成,有时间的朋友可以加我微信  : ying9567549   加好友备注博客园matlab技术     有需求也可联系此微信

 

 



 

标签:subplot,提取,图像,title,imshow,边缘,edge,Matlab,算子
From: https://www.cnblogs.com/-ying22/p/16844458.html

相关文章

  • 传统图像分割方法(基于阈值分割)
    阈值法:基本思想是基于图像的灰度特征来计算一个或多个灰度阈值,并将图像中每个像素的灰度值与阈值相比较,最后将像素根据比较结果分到合适的类别中。因此,该类方法最为关键的......
  • 文件更小,质量更高,大火的Stable Diffusion还能压缩图像?
    文件更小,质量更高,大火的StableDiffusion还能压缩图像?代码:code......
  • flink运行架构(图像版)
    自己总结的内容全部都画在一张图上了,下面的总图里的部分截图:  ......
  • Matlab编程基础
    “Matlab”是“Matrix Laboratory”的缩写,中文“矩阵实验室”,是强大的数学工具。本文侧重于Matlab的编程语言侧面,讲述Matlab的基本语法,以及用Matlab语言进行程序设计。值......
  • 基于Matlab的FIR滤波器设计与实现
    一、摘要前面一篇文章介绍了通过FDATool工具箱实现滤波器的设计,见“基于Matlab中FDATool工具箱的滤波器设计及相关文件的生成”,这里通过几个例子说明采用Matlab语言设......
  • 【跳频通信】基于MATLAB的跳频通信系统仿真
    1.软件版本matlab2015a2.系统程序clc;clear;closeall;warningoff;addpath'func\'addpath'func\mfiles\'loaddata.matfs=100e6;Nfft......
  • 基于等波纹最佳逼近法的FIR数字滤波器实现matlab仿真
    目录一、理论基础二、案例背景三、MATLAB核心代码四、仿真结论分析一、理论基础 等波纹最佳逼近法,其本质是一种优化算法,该方法有效克服了基于窗函数的FIR滤波器设......
  • 基于频率抽样法的FIR数字滤波器实现matlab仿真
    目录一、理论基础二、案例背景三、MATLAB核心代码四、仿真结论分析一、理论基础根据快速傅里叶变换的数学原理可知,对于一个任意长度的序列,通过对其频谱特性进行等间......
  • matlab矩阵的表示和简单操作
    一、矩阵的表示在MATLAB中创建矩阵有以下规则:a、矩阵元素必须在”[]”内;b、矩阵的同行元素之间用空格(或”,”)隔开;c、矩阵的行与行之间用”;”(或回车符)隔开;d、矩阵的元素可......
  • AWT+Swing实现百度图像识别
    1准备1.1在百度智能云中创建自己的应用,得到APIKey和SecretKey1.2maven导入SDK依赖2源码 importjava.net.URLEncoder;/***植物识别*/publicclassPlant......