Escolar Documentos
Profissional Documentos
Cultura Documentos
SEGMENTATION BASED
IN BORDERS
Point detection
To detect points in an image we can use a mask like this one:
‐1 ‐1 ‐1
‐1 8 ‐1
‐1 ‐1 ‐1
Using this in MATLAB would be very easy:
w = [‐1 ‐1 ‐1; ‐1 8 ‐1; ‐1 ‐1 ‐1]
g = abs(imfilter(double(f), w));
T = max(g(:)); % <‐‐ T is a limit value.
g = g >= T; % <‐‐ g is a logic matrix.
imshow(g);
The result would be, black if it didn't detect any point, and white for the pixels where it detected it.
Line detection
We can do it through masks:
‐1 ‐1 ‐1
2 2 2
‐1 ‐1 ‐1
% Horizontal
‐1 ‐1 2
‐1 2 ‐1
2 ‐1 ‐1
% 45°
‐1 2 ‐1
‐1 2 ‐1
‐1 2 ‐1
% Vertical
http://imgprocessing.tk/analysis/segmentationborders.html 1/5
12/31/2016 Segmentation based in borders
2 ‐1 ‐1
‐1 2 ‐1
‐1 ‐1 2
% ‐45°
For example, for 45°:
w = [2 ‐1 ‐1; ‐1 2 ‐1; ‐1 ‐1 2];
g = imfilter(double(f), w);
figure, imshow(g, []);
g = abs(g);
T = max(g(:));
g = g >= T;
figure, imshow(g);
Axis detection
1/2
g = (G x 2 + G y 2 ) g=Gx2+Gy21/2
The basic idea behind axis detection is to find places in the image where the intensity changes fast, using one
of these two criteria:
Finding places where the first derivative of the intensity is bigger than a given value.
Find places in the image where the second derivative crosses zero.
To detect axis:
[g, t] = edge(f, 'method', parameters)
Axis detection with Sobel filters
[g, t] = edge(f, 'sobel', T, dir)
Axis detection with Prewitt filters
[g, t] = edge(f, 'prewitt', T, dir)
Axis detection with Roberts filters
[g, t] = edge(f, 'roberts', T, dir)
Axis detection with LoG filters
http://imgprocessing.tk/analysis/segmentationborders.html 2/5
12/31/2016 Segmentation based in borders
[g, t] = edge(f, 'roberts', sigma)
Axis detection, the Canny detector
[g, t] = edge(f, 'canny', sigma)
How it works:
We perform a smoothing of the image with a Gaussian filter.
The gradients and their direction are calculated for each pixel. An axis point is defined as a point
that has a maximum in the direction of the gradient.
The algorithm filters the previous image with limits T1 and T2 , where T1 < T2 . Pixels with
values bigger than T2 are said to be "strong" axis pixels, pixels in between T1 and T2 are said to
be "weak" axis pixels.
Finally, the algorithm performs an "edge linking" and incorporates the weak axis pixels that have
a connexion of 8 with the group of the strong axis pixels.
Axis detection, the Hough transform
http://imgprocessing.tk/analysis/segmentationborders.html 3/5
12/31/2016 Segmentation based in borders
[h, theta, rho] = hough(f, dtheta, drho)
http://imgprocessing.tk/analysis/segmentationborders.html 4/5
12/31/2016 Segmentation based in borders
[r, c] = houghpeaks(h, numpeaks)
With the previous function we detect peaks in the transform that we want to transform into lines. We do that
through the function below:
lines = houghlines(f, theta, rho, r, c)
You can practice these concepts using snippet05
http://imgprocessing.tk/analysis/segmentationborders.html 5/5