Matlab code to find hand extremeties and centre of a hand after image segmentation.

Sir can you please tell me how to find centre and hand extremeties of hand image. I have attached the respective image here. Actually I want to automatically extract the region of vein patterns from the back of the palm. Please help me with the code.

 Réponse acceptée

10 commentaires

Actually sir I want to do wrist completion first because it is necessary for other images in the database to get correct centroid and hand extremeties. I couldn't understand the code you referred and failed to get the outcome for the same.
if true
% code
clear all; *bold*
close all;
fontSize = 13;
rgbImage = imread(imgetfile);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
grayImage = rgb2gray(rgbImage);
% Display the image.
subplot(2, 2, 2);
imshow(grayImage);
title('Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
b = grayImage<170;
b = imfill(b, 'holes');
% Label the image
labeledImage = bwlabel(b);
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','r','LineWidth',2 )
end
% Let's extract the biggest blob - that will be the hand.
allAreas = [measurements.Area];
[sortedAreas, sortingIndexes] = sort(allAreas, 'descend');
handIndex1 = sortingIndexes(1);
% Use ismember() to extract the hand from the labeled image.
handImage1 = ismember(labeledImage, handIndex1);
% Now binarize
handImage1 = handImage1 > 0;
% Display the binary image.
subplot(2, 2, 3);
imshow(handImage1);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
subplot(2,2,4);
imshow(handImage1);
title('binary image with border');
boundaries=bwboundaries(handImage1);
x = boundaries{1}(:, 2);
y = boundaries{1}(:, 1);
hold on;
plot(x, y, 'black', 'LineWidth', 2);
newImage = bwlabel(handImage1);
measurements = regionprops(newImage, 'Centroid', 'BoundingBox');
xCentroid = measurements.Centroid(1);
yCentroid = measurements.Centroid(2);
figure;
imshow(newImage);
title('Binary Image with Centroid Marked');
hold on;
plot(xCentroid, yCentroid, 'r*', 'MarkerSize', 10, 'LineWidth', 2);
end
Sir, I have attached my code and input image. I want to find centroid and hand extremeties of the segmented hand image. So, for wrist completion I tried to form a boundary. After getting wrist completion when I tried to find centroid of the hand then I got the centroid for binary image not for the image after formation of boundary(image after wrist completion). I want to solve this problem as when I go for another image (2nd image in the attachment) as input; I don't get the desired result. And my handImage is logical only. Please help with the MATLAB code for wrist completion so that I will be able to get correct centroid for hand.
Sir Manjiree Waikar,
in the image, I change to collor green. There is some points making a circular pattern in gray scale image. You can take max value of x-axys and the min value of x-axys of this green points. Doing (max_value_of_x_axys - min_value_of_y_axys) give us the calculated diameter. With the diameter you can segment the hand drawing a circle.
Correction: there is the biggest green bounding box two. The second max value and second min value should be used to calculated the diameter.
Thank you for responding sir. But I didn't understand exactly what to do and how to do.
Try this:
clear all; %*bold*
close all;
clc;
fontSize = 13;
rgbImage = imread(imgetfile);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
grayImage = rgb2gray(rgbImage);
% Display the image.
subplot(2, 2, 2);
imshow(grayImage);
title('Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
media = round(mean(mean(grayImage)));
% img_bin = imbinarize(grayImage,media);
% afterOpening = imopen(img_bin,se);
b = grayImage<media;
b = imfill(b, 'holes');
% Label the image
[rows, columns, numberOfColorBands] = size(grayImage);
circleCenterX = 120;
circleCenterY = 120; % square area 0f 500*500
circleRadius = 110; % big circle radius
circleImage = false(rows, columns);
[x, y] = meshgrid(1:columns, 1:rows);
circleImage((x - circleCenterX).^2 + (y - circleCenterY).^2 <= circleRadius.^2) = true;
b = and(circleImage,b);
labeledImage = bwlabel(b);
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
matrix = zeros(4,length(measurements));
vector = zeros(1,length(measurements));
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
matrix(:,k) = thisBB(:);
vector(k) = thisBB(2);
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','g','LineWidth',2 )
end
vector = sort(vector);
% Let's extract the biggest blob - that will be the hand.
allAreas = [measurements.Area];
[sortedAreas, sortingIndexes] = sort(allAreas, 'descend');
handIndex1 = sortingIndexes(1);
% Use ismember() to extract the hand from the labeled image.
handImage1 = ismember(labeledImage, handIndex1);
% Now binarize
handImage1 = handImage1 > 0;
se = strel('disk',5);
handImage1 = imerode(handImage1,se);
% Display the binary image.
subplot(2, 2, 3);
imshow(handImage1);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
subplot(2,2,4);
imshow(handImage1);
title('binary image with border');
boundaries=bwboundaries(handImage1);
x = boundaries{1}(:, 2);
y = boundaries{1}(:, 1);
hold on;
plot(x, y, 'black', 'LineWidth', 2);
newImage = bwlabel(handImage1);
measurements = regionprops(newImage, 'Centroid', 'BoundingBox');
xCentroid = measurements.Centroid(1);
yCentroid = measurements.Centroid(2);
figure;
imshow(newImage);
title('Binary Image with Centroid Marked');
hold on;
plot(xCentroid, yCentroid, 'r*', 'MarkerSize', 10, 'LineWidth', 2);
I create a circle image that select the area you want
You can optimize the circle radius
Thank you so much sir. It worked for me. Sir I want to know that which method should I use for automatic extraction of ROI with above output Image?
Is not functional the actual output image?

Connectez-vous pour commenter.

Plus de réponses (1)

First do background correction by dividing by an image of just the white sheet. Then ask regionprops for the centroid.

4 commentaires

Sir how to do the background correction?
Take a picture of just the white sheet background without the hand. Then take a picture with the hand and divide that by the no-hand background image.
Image Analyst, I don't know if it's correct to ask here. But: have you ever work with kinect?
No sir, I haven't worked with kinect.

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by