Kinect depth image segmentation

I want to segment the hand region alone from the kinect depth image that I have attached. As I am new to MATLAB and image processing I don't have any idea how to proceed on this . Can anyone give me a hand with this?

 Accepted Answer

Try this:
% Demo by Image Analyst
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 = 22;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = '5_depth.png';
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);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = rgbImage(:, :, 3);
else
grayImage = rgbImage;
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 1, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Binarize the image to get a mask.
mask = grayImage == 18;
mask = imfill(mask, 'holes');
% Take at most 3 blobs.
mask = bwareafilt(mask, 2);
% Blobs must be at least 10 pixels big:
mask = bwareaopen(mask, 10);
% Display mask image.
subplot(2, 1, 2);
imshow(mask);
hold on;
impixelinfo;
axis('on', 'image');
drawnow;
title('Mask, a Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
props = regionprops(mask, 'Area', 'Centroid');
allAreas = [props.Area]
centroids = vertcat(props.Centroid);
% Tell the user
message = sprintf('Done!\n\nThe hand area is %d pixels', sum(allAreas));
uiwait(helpdlg(message))

6 Comments

Thank you so much!!
If it turns out to be the best solution you get, please click the "Accept this answer" link. 🙂
Done sir! thank you once again.
Nivethitha M
Nivethitha M on 25 Apr 2022
Edited: Image Analyst on 25 Apr 2022
I want to do this segmentation for all the depth gesture images in the dataset and store the segmented images in the seperate processed dataset folder.Can you pls help me out with this. I have attached the dataset link below.
See the FAQ for how to process a sequence of files:
There are code samples there that you can adapt. Inside the loop, put some code to write your results to some output folder.
Thank you for your guidance!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!