Edge detection :gradients

Derivatives(just like the theory of the smart car)

Edges in an image is really about the derivatives respect to the image function.As you can see:

Edge detection :gradients_第1张图片
图片.png

These edges correspond to these extrema of the derivatives.

parital derivatives of an image

First we just make make the derivatives of the x or y directions.As you can see,the different templates we you to get the detivatives.

Edge detection :gradients_第2张图片
图片.png

sobel operator

It not only watches the center of the op(operator),but also watches the nearby pixel.It is also the default op of the fun() in matlab:imgredientxy()

Edge detection :gradients_第3张图片
图片.png

And other ops are listed below:

Edge detection :gradients_第4张图片
图片.png

Matlab basically understand all of these:`

% 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

In the real world

What I'v said won't work without some extra handling!
The F(x) in the real word would be like this:

Edge detection :gradients_第5张图片
图片.png

The noise has cause us to have the positive and negative derivatives all over the place.

Edge detection :gradients_第6张图片
图片.png

So we basically apply smooth gradients somehow and look for some peaks.
And why we can do that?Because the linearity of the convolution as we can see below.We can apply the f before our derivatives.

图片.png
Edge detection :gradients_第7张图片
图片.png

2-D derivatives to find the maximum

Edge detection :gradients_第8张图片
图片.png

你可能感兴趣的:(Edge detection :gradients)