Can we plot the boundary of an image??
Show older comments
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
More Answers (2)
Walter Roberson
on 5 May 2015
0 votes
7 Comments
BlueBee77
on 5 May 2015
Walter Roberson
on 6 May 2015
You have the difficulty that the outlying points move around and exchange positions. You need to track left leg separately from right leg, for example, and that means you need to distinguish whether the leg that is "more x" is the left or right leg. That calls for tracking, not just static analysis. For example an arm might be at the same location as the leg during the swing, so there might be fewer than 5 major outlying points in any one image. When you don't give us this kind of information in advance, anything we suggest is not likely to work.
BlueBee77
on 29 May 2015
Image Analyst
on 29 May 2015
indexes is an array, so x(k) is also an array. Try it this way.
for k = 1 : length(indexes)
line([x(indexes(k)), Centroid(1)], [y(indexes(k)),Centroid(2) ], 'Color', 'r', 'LineWidth', 2);
end
BlueBee77
on 29 May 2015
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
on 29 May 2015
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
BlueBee77
on 31 May 2015
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
on 31 May 2015
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!