Can we plot the boundary of an image??

2 ビュー (過去 30 日間)
BlueBee77
BlueBee77 2015 年 5 月 5 日
コメント済み: BlueBee77 2015 年 5 月 31 日
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

採用された回答

Image Analyst
Image Analyst 2015 年 5 月 5 日
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 件のコメント
Walter Roberson
Walter Roberson 2015 年 5 月 5 日
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 2015 年 5 月 6 日
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.

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 5 月 5 日
You might be able to take advantage of the Extrema property of regionprops
  7 件のコメント
Image Analyst
Image Analyst 2015 年 5 月 29 日
Not really sure. Why don't you attach 'silhouete.jpg' so we can run your code with your actual image?
BlueBee77
BlueBee77 2015 年 5 月 29 日
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

サインインしてコメントする。


Image Analyst
Image Analyst 2015 年 5 月 29 日
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 件のコメント
Image Analyst
Image Analyst 2015 年 5 月 31 日
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 2015 年 5 月 31 日
OK,and once again thanks alot

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by