Kinect depth image segmentation

조회 수: 3 (최근 30일)
Nivethitha M
Nivethitha M 2022년 4월 23일
댓글: Nivethitha M 2022년 4월 25일
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?

채택된 답변

Image Analyst
Image Analyst 2022년 4월 23일
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
Image Analyst
Image Analyst 2022년 4월 25일
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.
Nivethitha M
Nivethitha M 2022년 4월 25일
Thank you for your guidance!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by