
Kinect depth image segmentation
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Nivethitha M
el 23 de Abr. de 2022
Comentada: Nivethitha M
el 25 de Abr. de 2022
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?
0 comentarios
Respuesta aceptada
Image Analyst
el 23 de Abr. de 2022
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 comentarios
Image Analyst
el 25 de Abr. de 2022
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!