基于八方向的sobel算子高精度边缘提取检测算法matlab仿真

目录

一、理论基础

1.1 传统算法概述

1.2 8方向sobel算法

二、核心程序

三、仿真测试结果

作者ID :fpga和matlab
CSDN主页:https://blog.csdn.net/ccsss22?type=blog
擅长技术:
1.无线基带,无线图传,编解码
2.机器视觉,图像处理,三维重建
3.人工智能,深度学习
4.智能控制,智能优化
5.其他

一、理论基础

 

 

1.1 传统算法概述

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1.2 8方向sobel算法

sobel算子按8方向改进,hough线变换、圆变换检测出直路,弯路,以及十字路口。Sobel边缘检测算子对像素灰度值做了加权平均, 提供了较为连续的边缘方向信息。针对传统图像边缘检测方法检测效果不理想的问题,提出一种基于八方向Sobel算子的边缘检测算法.采用0°、22.5°、45°、67.5°、90°、112.5°、135°、157.5°8个方向的模板进行检测,能较好地检测出不同方向的边缘.在检测过程中,考虑到邻域内像素到中心像素距离不同,对中心像素的贡献不同,算法根据该像素到中心像素欧氏距离对邻城内像素进行加权,使得距中心像素越近,其权值越大.实验表明,算法检测出的图像边缘较为完整,轮廓线清晰且连续性较好.

 

 利用八个方向的sobel边缘检测,其中为防止灰度值溢出对灰度值进行一个扩大和缩放的过程,可以检测出八个方向的灰度梯度值,检测出的边缘更加平缓连续。 

二、核心程序

clc;
clear;
close all;
warning off;
addpath 'func\'

%读取图像
I1 = imread('image\1.jpg');
I1 = imresize(I1,2);
[R,C,K] = size(I1);
if K == 3
I2 = rgb2gray(I1);
else
I2 = I1;
end


figure(1);
subplot(221);
imshow(I2);
title('原始图像');

%阴影分析
[B,I1yy] = func_yydel(I1);
subplot(222);
imshow(I1yy);
title('阴影检测');
%道路提取
III = func_daolu(I2,B);

subplot(223);
imshow(III,[]);
title('道路提取');


%高斯滤波
III2 = func_gaussfilter(III);
subplot(224);
imshow(III2,[]);
title('高斯滤波图像');
figure(2);
subplot(231);
imshow(I1)
%**************************************************************************
%**************************************************************************
%本文提出的算法
%本文提出的算法
tic;
[X2,Y2] = func_sobel8(III2);
toc;
Times5 = toc;
disp('仿真时间:');
Times5
figure(2);
subplot(232);
imshow(I1)
hold on;
for k = 1:length(X2)
plot(X2(k),Y2(k),'r.','LineWidth',1);
end
title('8方向改进Sobel算法的道路识别结果');
%**************************************************************************
%**************************************************************************
%Hough
%Hough
tic;
[accum,axis_rho,axis_theta,lineprm,lineseg] = func_Hough(III2,8,0.15);
toc;
Times1 = toc;
disp('仿真时间:');
Times1

figure(2);
subplot(233);
imagesc(I1);
colormap('gray');
axis image;
hold on
func_drawlines(lineseg);
title('基于Hough变换的道路检测');



%**************************************************************************
%**************************************************************************
%sobel
%sobel
tic;
[X,Y] = func_Sobel(III2);
toc;
Times2 = toc;
disp('仿真时间:');
Times2
figure(2);
subplot(234);
imshow(I1)
hold on;
for k = 1:length(X)
plot(X(k),Y(k),'r.','LineWidth',3);
end
title('基于Sobel变换的道路检测');
%**************************************************************************
%**************************************************************************
%canny
%canny
tic;
[X,Y] = func_Canny(III2);
toc;
Times3 = toc;
disp('仿真时间:');
Times3
figure(2);
subplot(235);
imshow(I1)
hold on;
for k = 1:length(X)
plot(X(k),Y(k),'r.','LineWidth',3);
end
title('基于Canny变换的道路检测');



%**************************************************************************
%**************************************************************************
%Prewitt
%Prewitt
tic;
[X,Y] = func_Prewitt(III2);
toc;
Times4 = toc;
disp('仿真时间:');
Times4
figure(2);
subplot(236);
imshow(I1)
hold on;
for k = 1:length(X)
plot(X(k),Y(k),'r.','LineWidth',3);
end
title('基于Prewitt变换的道路检测');

figure;
bar([Times1,Times2,Times3,Times4,Times5]);
title('各个算法仿真时间(Hough,Sobel,Canny,Prewitt,8方向改进Sobel)');

 

 

三、仿真测试结果

步骤一:道路提取和阴影消除以及高斯滤波

 

 步骤二:道路提取和多个个算法的仿真结果对比

 

 仿真时间对比如下所示: 

 

 从上面的仿真时间对比可知,改进后的算法,其性能最优,但是由于需要同时提取8个方向的边缘信息,因此,整个算法的仿真时间最久。

A09-48

posted @ 2022-10-21 22:14  fpga和matlab  阅读(699)  评论(0编辑  收藏  举报