Can we plot the boundary of an image??

5 views (last 30 days)
I am working on a project of object detection (Human). I have segmented the foreground and have calculated boundaries and centroid of the object. I want to connect the centroid to extreme points like hands, legs and head (in shape of a star). Can anyone help me how to find and connect those extreme points to centroid. Thanks in advance for your help

Accepted Answer

Image Analyst
Image Analyst on 5 May 2015
Use bwboundaries() to get the coordinates of the outline of your blob (human). Then pass them in to convhull() to get the convex hull, which is the official name of the extreme points you're talking about.
  5 Comments
Walter Roberson
Walter Roberson on 5 May 2015
Try with
x = boundaries{1}(:,2);
y = boundaries{1}(:,1);
The documentation indicates
bwboundaries returns B, a P-by-1 cell array, where P is the number of objects and holes. Each cell in the cell array contains a Q-by-2 matrix. Each row in the matrix contains the row and column coordinates of a boundary pixel. Q is the number of boundary pixels for the corresponding region.
You might want to use the 'noholes' option.
Image Analyst
Image Analyst on 6 May 2015
Convex hull will give you too many points for that. You need to choose just a few, like 5. I know people have done this and you have probably seen the papers. If not, look here in VIsion Bib for papers on pose and gait analysis. They will tell you how to do it better than me because they have worked for years in the area and published papers on what you want to do, and I haven't.

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 5 May 2015
You might be able to take advantage of the Extrema property of regionprops
  7 Comments
Image Analyst
Image Analyst on 29 May 2015
Not really sure. Why don't you attach 'silhouete.jpg' so we can run your code with your actual image?
BlueBee77
BlueBee77 on 29 May 2015
With this image, its not giving correct output, i don't know why. But with my human detection video its is working well, only it crashes and is giving warnings. U can test on this image, i hope u figure it out. I will be really thankful

Sign in to comment.


Image Analyst
Image Analyst on 29 May 2015
Palwasha:
I fixed your code. The main problem is that your binarized image doesn't have the man as the white foreground. Your surrounding background is actually considered the foreground so I had to invert your image. Here is the fixed code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
grayImage = imread('silhouete.jpg');
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 1, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Threshold the image.
binaryImage = ~im2bw(grayImage);
% Display the original gray scale image.
subplot(2, 1, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Label the image
labeledImage = bwlabel(binaryImage);
s= regionprops(labeledImage, 'Centroid');
centroids = [s.Centroid];
Centroid= centroids';
boundaries = bwboundaries(binaryImage, 'noholes');
x = boundaries{1}(:,2);
y = boundaries{1}(:,1);
indexes = convhull(x, y);
% Plot the convex hull in magenta
hold on;
plot(x(indexes), y(indexes), 'm-', 'LineWidth', 2);
% Plot lines from the centroid to the convex hull vertices.
for k = 1 : length(indexes)
line([x(indexes(k)), Centroid(1)], [y(indexes(k)),Centroid(2) ], 'Color', 'r', 'LineWidth', 2);
end
  3 Comments
Image Analyst
Image Analyst on 31 May 2015
I don't know, but there are papers on that here: http://www.visionbib.com/bibliography/contents.html. Pick one and code it up.
BlueBee77
BlueBee77 on 31 May 2015
OK,and once again thanks alot

Sign in to comment.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!