Sunday, February 14, 2010

[Activity] 2 : Silhouette Processing

Activity 2: Silhouette Processing

In this activity, we try to extract the contour of an object and replace the edge by the Freeman Vector code. This method has been shown to be an effective tool in biometric identification by utilizing the gait pattern of persons. It has been shown that when the Freeman Vector of a person's gait pattern is properly-aligned, it shows consistency and distinct periodicity that can be used to identify a person. The whole process is summarized by the image below.[1]

Block diagram of the method [1]

The first step in this activity is to take a picture of an object with relatively good contrast compared to its background. This would make the extraction of its contour/edge much easier. The image used for this activity is shown below.


Input image

After some morphological operations (turning the image to grayscale then binary, performing edge detection), the resulting image is shown below.

Resulting image after edge detection.

The image above will then be the used to extract the Freeman Vector code. Arbitrarily choosing a starting pixel, the values for the other pixels will be replaced by the value depending on its position relative to the previously processed pixel. The value is determined by the image below where point (x,y) is the current pixel location.


Freeman vector value determiner


The Freeman vector derived from the contour/edge information of the object is then further processed to retrieve new curvature string values. This new vector string contains positive, negative and zero strings that describe whether a certain the part of the contour is convex, concave or relatively straight, respectively. Between the Freeman vector and the curvature string values, there is an intermediate vector in between.

From the Freeman vector, we get the difference between two adjacent values. In this step, the first element of the vector is treated as the last to maintain continuity. From this intermediate vector, we perform a running sum of three adjacent values to retrieve the curvature string. The processes is illustrated below.

Curvature String extraction from the Freeman Vector Chain

The output of the program is shown below. Positive string values for convex contour, negative for concavities and strings of zero for straight lines.

Positive values for convexities

Negative values for concavities

Zero string for straight lines

Code Listing:

function freeman(image)
image = rgb2gray(imread(image));
BW = im2bw(image, 0.16);
BW = imresize(BW, 0.5);
% se = strel('disk', 10);
% BW = imclose(BW, se);
se = strel('disk', 3);
BW = imdilate(BW, se);
BW = edge(double(BW), 'canny');

figure, imshow(BW);
%
x1 = 0;
y1 = 0;

%search for the upperleftmost pixel
[x, y] = size(BW);
for row=1:1:x
for col=1:1:y
if (BW(row, col) == 1),
x1 = row;
y1 = col;
break;
end
end
end
pixels = bwtraceboundary(BW, [x1,y1], 'N');
[counter, temp] = size(pixels);
freemanvec = zeros(counter,1);
for j=2:1:counter
diff_x = pixels(j,1) - pixels(j-1,1);
diff_y = pixels(j,2) - pixels(j-1,2);
if (diff_x == -1) && (diff_y == -1)
freemanvec(j) = 1;
elseif (diff_x == 0) && (diff_y == -1)
freemanvec(j) = 2;
elseif (diff_x == 1) && (diff_y == -1)
freemanvec(j) = 3;
elseif (diff_x == 1) && (diff_y == 0)
freemanvec(j) = 4;
elseif (diff_x == 1) && (diff_y == 1)
freemanvec(j) = 5;
elseif (diff_x == 0) && (diff_y == 1)
freemanvec(j) = 6;
elseif (diff_x == -1) && (diff_y == 1)
freemanvec(j) = 7;
elseif (diff_x == -1) && (diff_y == 0)
freemanvec(j) = 8;
end
end
freemanvec(1) = freemanvec(length(freemanvec));

gradient = zeros(counter,1);
runsum = zeros(counter,1);

for i=1:1:counter-1
gradient(i) = freemanvec(i+1) - freemanvec(i);
end
gradient(length(freemanvec)) = gradient(1);

for i=2:1:counter-1
runsum(i) = gradient(i-1) + gradient(i) + gradient(i+1);
end
runsum(1) = gradient(1) + gradient(2) + gradient(counter-1);
figure, plot([1 250],[1 250],'Color', 'w')
for i=1:1:counter
row = pixels(i,1);
col = pixels(i,2);
text(col, row, num2str(runsum(i)));
end;

I give myself a grade of 10 for accomplishing the objectives for this activity.


References:
[1] Soriano, et al., "Curve Spreads - a biometric from front-view gait video", Pattern Recognition Letters 25 (2004) 1595 - 1602
[2] Activity 2: Silhouette Processing Activity Sheet, Physics 305, M. Soriano

No comments:

Post a Comment