Can we plot the boundary of an image??
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
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
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
2015-5-5
7 个评论
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?
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177194/image.jpeg)
3 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing and Computer Vision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!