how to get part of the object contour ?
Show older comments
I'm working to classify objects as human or non-human. My research focuses on the shape detection. I tried to use the function edge in MATLAB but I do not know how to find the boundary edge for the head, neck and shoulders only for a human object from an image. In another words I want to ignore the internal edges; I just want the boundary edge. Can anyone help me in this? i want to get this part of the object and it is coordinates ?

Accepted Answer
More Answers (2)
Image Analyst
on 8 Jun 2017
1 vote
Hard to tell without the original image with tons of edges in it. It looks like you just uploaded the final image with one or two edges. What if there were other edges in there but below that curve, but were still accessible coming from underneath? What defines "outer" to you? Anyway, you might use the new boundary() function. Please upgrade your old version of MATLAB, unless you want to write that functionality in all by yourself.
2 Comments
malek al-nawashi
on 8 Jun 2017
Edited: Walter Roberson
on 10 Jun 2017
Image Analyst
on 13 Jun 2020
This will do it:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
fprintf('Beginning to run %s.m ...\n', mfilename);
%-----------------------------------------------------------------------------------------------------------------------------------
% Read in image.
folder = pwd;
baseFileName = 'image.jpeg';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Display the RGB image full size.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis('on', 'image');
caption = sprintf('Original Image : "%s"', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
hFig1 = gcf;
hFig1.Units = 'Normalized';
hFig1.WindowState = 'maximized';
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
hFig1.Name = 'Demo by Image Analyst';
% Do color segmentation to get the mask.
hsvImage = rgb2hsv(rgbImage);
% Threshold the saturation image at 0.2
mask = hsvImage(:, :, 2) > 0.2;
% Fill holes
mask = imfill(mask, 'holes');
% Take the largest blob only.
mask = bwareafilt(mask, 1);
% Display the binary image.
subplot(2, 2, 2);
imshow(mask, []);
axis('on', 'image');
caption = sprintf('Mask Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Get the boundaries of the mask
maskBoundary = bwboundaries(mask);
maskBoundary = maskBoundary{1}; % Extract from cell. Is in (row, column) format, not (x, y).
% Get x and y for the boundary
x = maskBoundary(:, 2);
y = maskBoundary(:, 1);
% Make an all white image
whiteImage = 255 * ones(rows, columns, 3, 'uint8');
% Display the RGB image full size.
subplot(2, 2, 3);
imshow(whiteImage, []);
hold on;
plot(x, y, 'b-', 'LineWidth', 3);
axis('on', 'image');
caption = sprintf('Initial Boundary');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% It's hard to see single pixels because they get subsampled away during display,
% so let's use plot to plot a really thick line over it.
% Display the RGB image full size.
subplot(2, 2, 4);
imshow(whiteImage, []);
hold on;
caption = sprintf('Head and Shoulders');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% We only want the head and shoulders, so let's assume that the shoulders are 170 pixels below the top of the head.
shoulderLine = min(y) + 170;
yline(shoulderLine, 'Color', 'r', 'LineWidth', 2);
% Extract only the coordinates with y less than shoulderLine
indexes = y < shoulderLine;
xhs = x(indexes);
yhs = y(indexes);
plot(xhs, yhs, 'b-', 'LineWidth', 3);

Walter Roberson
on 10 Jun 2017
0 votes
Your algorithm is doomed to failure.
5 Comments
QuestionsAccount
on 13 Jun 2020
@malek al-nawashi Did you find the ans of your Question?
Image Analyst
on 13 Jun 2020
I posted an answer here: In a comment above.
Obviously it works only for the particular super-simple image he posted.
D. Frank
on 22 Jul 2020
Hello guys, is there any way to take full human body (should be obese) from a very noise back ground to take the body joint contour and calculate the body width? Where should i start? Thank youu.
Image Analyst
on 22 Jul 2020
I'm sure there is. Here are four links to start with:
D. Frank
on 24 Jul 2020
i would like to say thank you a lot xD
Categories
Find more on Convert Image Type 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!

