Automatic Region of Interest Extraction- Palm of Hand

3 views (last 30 days)
Does anybody have any ideas as to how I could go about extracting the palm from images similar to those attached as a region of interest automatically? I have a large number of the images and would prefer to have some software that could recognise and extract the palm automatically rather than manually extracting it myself but there doesn't seem to be any easy way of going about it.

Answers (2)

Image Analyst
Image Analyst on 11 Dec 2017
First of all, use a black background, not one that's so similar to the gray intensity of your palm. Then you can just threshold and find the Euclidean Distance Transform with bwdist:
hand = grayImage > someThreshold;
edtImage = bwdist(~hand);
palmMask = edtImage > someValue;
  4 Comments
Caolan Furey
Caolan Furey on 11 Dec 2017
Possibly, I scanned the images myself, I could look into taking pictures against a black background if it would make extracting the region of interest much easier.
Image Analyst
Image Analyst on 11 Dec 2017
Yes it would. Black velvet is about the best black background you can get. It's very dark. In the meantime, you could mock up something in Photoshop by painting the background black.

Sign in to comment.


Image Analyst
Image Analyst on 11 Dec 2017
Here's a start:
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 short g;
format compact;
fontSize = 25;
%===============================================================================
% Read in a standard MATLAB gray scale demo image.
folder = pwd;
baseFileName = 'image1.jpg';
% Get the full filename, with path prepended.
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
grayImage = 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(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Plot the histogram.
subplot(2, 3, 2);
histogram(grayImage);
grid on;
title('Histogram of original image', 'FontSize', fontSize, 'Interpreter', 'None');
% Threshold the image.
binaryImage = grayImage > 50;
% Extract the largest blob.
binaryImage = bwareafilt(binaryImage, 1);
% Fill any holes.
binaryImage = imfill(binaryImage, 'holes');
% Display the image.
subplot(2, 3, 3);
imshow(binaryImage, []);
axis on;
caption = sprintf('Binary Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
drawnow;
% Get the Euclidean Distance transform.
edtImage = bwdist(~binaryImage);
% Display the image.
subplot(2, 3, 4);
imshow(edtImage, []);
axis on;
caption = sprintf('Distance Transform Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
drawnow;
% Threshold the EDT image at 110 since that's how wide the fingers are.
palmMask = edtImage > 130;
% Extract the largest blob.
% Extract the largest blob.
palmMask = bwareafilt(palmMask, 1);
% Display the image.
subplot(2, 3, 5);
imshow(palmMask, []);
axis on;
caption = sprintf('Palm Mask Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
drawnow;
% Use the palm mask on the original image.
maskedImage = grayImage; % Initialize
maskedImage(~palmMask) = 0; % Erase everything outside the mask.
% Display the image.
subplot(2, 3, 6);
imshow(maskedImage, []);
axis on;
caption = sprintf('Masked Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
drawnow;
  3 Comments
Image Analyst
Image Analyst on 10 Jan 2018
Edited: Image Analyst on 10 Jan 2018
You'll need to invert your original binary image first since your hand is black rather than white.
Your image is bigger than what I posted for so you're going to have to use a threshold bigger than 30 pixels. Try 50 or 100 or something.
Gaoshq
Gaoshq on 11 Jan 2018
Thanks very very much for your help. It works very well.

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!