detection on an imageThis
experiment explores line
detection (for image
analysis) with Matlab.
an image can be expressed with two matrices (one matrix being the color palette
and the other one being the reference
to those colors), we can manipulate pictures
or images by modifying both the map (palette) and the matrix containing
values to be displayed.
that you first read this
article on RGB images.
experiment draws some squares in different colors. These are the coded
We choose the 'jet' palette
We define a 90 x 90 matrix, and make it all ones.
This means that the 'background' will be the first
found in our palette
r = 90;
c = r;
Define our colors in very specific areas of the matrix
40, 10 : 40) = 20;
60, 30 : 60) = 40;
80, 50 : 80) = 60;
40, 30 : 40) = 30;
60, 50 : 60) = 50;
Display the image and 'turn off' the axes
This is the resulting
image or picture:
we’ll inspect the matrix
pixel-by-pixel (a pixel is a picture element).
find different colors between two consecutive pixels, we’ll write it
another matrix that finally will be shown.
have different approaches to the inpection of consecutive pixels.
do these operations, for example (if i and j represent rows
and columns of the matrix):
j) - W(i,j)) + (W(i+1, j) - W(i,j)) +...
j-1) - W(i,j)) + (W(i, j+1) - W(i,j));
j) - W(i,j))^2 + (W(i+1, j) - W(i,j))^2 +...
j-1) - W(i,j))^2 + (W(i, j+1) - W(i,j))^2;
result is greater than 0 it means that we’ve found different objects
within a picture and we can annotate that information on another
matrix, to be
the full code to the first approach:
[r, c] =
for i = 2 :
for j = 2 : c-1
cl(i, j) = (W(i-1, j) - W(i,j)) +
(W(i+1, j) - W(i,j)) +...
(W(i, j-1) - W(i,j)) + (W(i,
j+1) - W(i,j));
if cl(i,j) > 0
produces this image:
change some lines in the code to achieve our second approach:
= (W(i-1, j) - W(i,j))^2 + (W(i+1, j) - W(i,j))^2 +...
(W(i, j-1) - W(i,j))^2 + (W(i, j+1)
produces this picture:
we have performed an edge or line detection from our original image
'Line Detection' to home
'Line Detection' to 'Matlab Programming'