边缘检测

您所在的位置:网站首页 检测i2的方法 边缘检测

边缘检测

2023-06-17 10:03| 来源: 网络整理| 查看: 265

边缘检测——利用edge函数

在这里插入图片描述

Canny边缘检测器 【g,t】=edge(img,‘canny’,T,sigma) 其中T为包含两个阈值的二元行向量,sigma为高斯平滑的标准差,g为处理后的逻辑图像,t为算法使用的两个阈值 Img=imread('F:\20191214162428.jpg'); I=rgb2gray(Img); I=tofloat(I); I2=edge(I,'canny',[0.04,0.1],3); figure,imshow(I2); %---------------------------------------------------------------------% function [out,revertclass] = tofloat(inputimage) % 类型转换 % 单纯的取 x 用的匿名函数句柄(玩的有点花) identify = @(x) x; % 将输入转换为单精度的函数句柄 tosingle = @im2single; table = {'uint8',tosingle,@im2uint8 'uint16',tosingle,@im2uint16 'logical',tosingle,@logical 'double',identify,identify 'single',identify,identify}; % strcmp(s1,s2),输入字符串的数组可以说任意类型组合 % find 找出其中的真值 classIndex = find(strcmp(class(inputimage),table(:,1))); if isempty(classIndex) error('不支持的图像类型'); end % 找到对应的转换类型 out = table{classIndex,2}(inputimage); % 记录对应逆转换类型 revertclass = table{classIndex,3}; end

在这里插入图片描述 2. Sobel边缘检测器 【g,t】=edge(img,‘sobel’,T,dir) 其中T为一个阈值,与梯度比较,dir为想要检测的边缘方向,g为处理后的逻辑图像,t为算法使用的阈值

Img=imread('F:\20191214162428.jpg'); I=rgb2gray(Img); I=tofloat(I); [g,t]=edge(I,'sobel',0.1); figure,imshow(g); %---------------------------------------------------------------------% function [out,revertclass] = tofloat(inputimage) % 类型转换 % 单纯的取 x 用的匿名函数句柄(玩的有点花) identify = @(x) x; % 将输入转换为单精度的函数句柄 tosingle = @im2single; table = {'uint8',tosingle,@im2uint8 'uint16',tosingle,@im2uint16 'logical',tosingle,@logical 'double',identify,identify 'single',identify,identify}; % strcmp(s1,s2),输入字符串的数组可以说任意类型组合 % find 找出其中的真值 classIndex = find(strcmp(class(inputimage),table(:,1))); if isempty(classIndex) error('不支持的图像类型'); end % 找到对应的转换类型 out = table{classIndex,2}(inputimage); % 记录对应逆转换类型 revertclass = table{classIndex,3}; end

在这里插入图片描述

[g,t]=edge(I,'sobel',0.1,'vertical');

在这里插入图片描述

Img=imread('F:\20191214162428.jpg'); I=rgb2gray(Img); I=tofloat(I); w1=[-2 -1 0;-1 0 1;0 1 2];%最强边缘为-45度方向的边缘 w2=[0 1 2;-1 0 1;-2 -1 0];%最强边缘为+45度方向的边缘 I2=imfilter(I,w1,'replicate'); T=0.3*max(abs(I2(:))); I3=I2>=T; figure,imshow(I3); I4=imfilter(I,w2,'replicate'); T2=0.3*max(abs(I4(:))); I5=I4>=T2; figure,imshow(I5); %---------------------------------------------------------------------% function [out,revertclass] = tofloat(inputimage) % 类型转换 % 单纯的取 x 用的匿名函数句柄(玩的有点花) identify = @(x) x; % 将输入转换为单精度的函数句柄 tosingle = @im2single; table = {'uint8',tosingle,@im2uint8 'uint16',tosingle,@im2uint16 'logical',tosingle,@logical 'double',identify,identify 'single',identify,identify}; % strcmp(s1,s2),输入字符串的数组可以说任意类型组合 % find 找出其中的真值 classIndex = find(strcmp(class(inputimage),table(:,1))); if isempty(classIndex) error('不支持的图像类型'); end % 找到对应的转换类型 out = table{classIndex,2}(inputimage); % 记录对应逆转换类型 revertclass = table{classIndex,3}; end

在这里插入图片描述 在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3