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

 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

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:

To detect axis:

[g, t] = edge(f, 'method', parameters)

Axis detection with Sobel filters

[g, t] = edge(f, 'sobel', T, dir)

where f is the image, T is the limit (optional), dir is the direction of filtering ('horizontal', 'vertical', or 'both' (default)), g is the image of the axis and t is the limit.

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

[g, t] = edge(f, 'roberts', sigma)

where sigma is the standard deviation.

Axis detection, the Canny detector

[g, t] = edge(f, 'canny', sigma)

How it works:

Axis detection in the image of an old house

Axis detection, the Hough transform

Hough transform

Hough transform

Hough transform

[h, theta, rho] = hough(f, dtheta, drho)

where f is the image, dtheta and drho specify the spacing in each axis, H is the Hough transform, theta is a vector that contains the angle for each sample and rho is a vector that contains the ρ value for each sample.

Axis detection in the image of an old house

[r, c] = houghpeaks(h, numpeaks)

Here, h is the Hough transform, numpeaks is the number of peaks we want to detect, r is a vector with the position in rows of the peaks and c is a vector with the position in columns of the peaks.

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)

where f is the image from which we are going to extract the lines, theta and rho are the vectors that we obtain from the Hough transform, and r and c are the vectors that houghpeaks returns.

You can practice these concepts using snippet05.