[cv]edge detection: gradients

本文介绍了如何使用图像处理技术来检测图片中的边缘。主要内容包括理解边缘的基本概念、梯度的数学表示及其在边缘检测中的应用。通过Matlab示例展示了如何实现Sobel算子进行边缘检测,并给出了具体步骤。
部署运行你感兴趣的模型镜像

usually, filter is used to find a specific pattern in the pictures.
If we want to find lines and edges in the picture, firstly we think about gradients.
画图的时候,光画出线条就可以表达很多信息。
不要轻视线条,其中包含了太多的信息。

edges

线条的成因:
1. 物体表面的不连续,形状变化
2. 表面颜色不连续
3. 光照强度不连续
4. depth discontinuity,物体与背景的差异
change-boundary

detection edges

recall images as functions.
each location (x,y) has a value.
imageasfunctions
in the above picture, edges like the steep cliffs.
so, our basic idea: find a neighborhood with strong signs of change.
But, there are two problems:
1. neighborhood size
2. how to detect changes

derivative and edges

derivative and edges
differential operator
differential operator
image gradient
image-gradient

the gradient direction is given by : tan1(fy/fx)
The amount of change is given by the gradient magnitude:f=(fx)2+(fy)2
这里写图片描述

finite difference

fxf(x+1,y)f(x,y)1
it was called right derivative.
finite-difference

differential operator

discrete gradient

sobel operator

sobel-operator
in matlab, there is a function imgradientxy which uses sobel operator but isn’t divided by 8.
So you need add a step to get that output divided by 8.

imgradientxy - Directional gradients of an image
This MATLAB function returns the directional gradients, Gx and Gy, the same size
as the input image I.
[Gx,Gy] = imgradientxy(I)
[Gx,Gy] = imgradientxy(I,method)
[gpuarrayGx,gpuarrayGy] = imgradientxy(gpuarrayI,_)

sobel-operator0
well-known-gradient

filter = fspecial('sobel'); % y direction
res = imfilter(double(img), filter);
imagesc(res);
colormap gray;
imshow(res);

corr-gradient

imfilter function use correlation by default.

% Gradient Direction
function result = select_gdir(gmag, gdir, mag_min, angle_low, angle_high)
    % TODO Find and return pixels that fall within the desired mag, angle range
    result = gmag>= mag_min & gdir >= angle_low & gdir <= angle_high;
endfunction

pkg load image;

%% Load and convert image to double type, range [0, 1] for convenience
img = double(imread('octagon.png')) / 255.; 
imshow(img); % assumes [0, 1] range for double images

%% Compute x, y gradients
[gx gy] = imgradientxy(img, 'sobel'); % Note: gx, gy are not normalized

%% Obtain gradient magnitude and direction
[gmag gdir] = imgradient(gx, gy);
imshow(gmag / (4 * sqrt(2))); % mag = sqrt(gx^2 + gy^2), so [0, (4 * sqrt(2))]
imshow((gdir + 180.0) / 360.0); % angle in degrees [-180, 180]

%% Find pixels with desired gradient direction
my_grad = select_gdir(gmag, gdir, 1, 30, 60); % 45 +/- 15
imshow(my_grad);  % NOTE: enable after you've implemented select_gdir

octagon

octagon-mag

octagon-direct

select

real-world
smooth
2nd-derivative-find-peak

linear-property

您可能感兴趣的与本文相关的镜像

Wan2.2-T2V-A5B

Wan2.2-T2V-A5B

文生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matdodo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值