To find the coordinates of the following image?

33 views (last 30 days)
I want to find the coordinates of the middle fingure in both hands.
  4 Comments
Image Analyst
Image Analyst on 1 Nov 2020
Sir, can you please provide the separate images? (Not a screenshot but the actual images).

Sign in to comment.

Answers (3)

Shantanu Dwivedi
Shantanu Dwivedi on 30 Oct 2020
You can Select points in an image interactively using the ‘getpts’ command.
1) figure
imshow(‘ImageName.tif);
2) [X,Y] = getpts;
3) Double click on the point whose coordinates are to be found.
4) X and Y will store the x and y coordinates of that point respectively.
Refer the following documentation for more information on ‘getpts’ method.

Image Analyst
Image Analyst on 30 Oct 2020
Try this:
Here's a start:
grayImage = rgb2gray(rgbImage);
mask = grayImage > 128; % or whatever value works to get the hand.
mask = imfill(mask, 'holes');
mask = bwareafilt(mask, 1); % Take largest blob.
props = regionprops(mask, 'BoundingBox');
xLeft = props.BoundingBox(1)
xRight = xLeft + props.BoundingBox(3)
hold on;
rectangle('Position', props.BoundingBox, 'EdgeColor', 'y', 'LineWidth', 2)
You can easily determine whether the hand is oriented like on the left of right by splitting the mask into the top half and bottom half and finding if the centroid of bottom half is to the left or right of the top half
topHalf = false(size(mask));
[rows, columns] = size(mask);
topHalf(floor(rows/2)+1:end, :) = false; % Erase bottom half.
propsTop = regionprops(topHalf, 'Centroid');
bottomHalf = false(size(mask));
bottomHalf(1:floor(rows/2), :) = false; % Erase top half.
propsBottom = regionprops(topHalf, 'Centroid');
if propsTop.Centroid(1,1) < propsBottom.Centroid(1,1)
% Forearm is on the right.
xMiddle = xLeft; % Middle finger is on the left.
else
% Forarm is on the left
xMiddle = xRight; % Middle finger is on the right.
end

Image Analyst
Image Analyst on 1 Nov 2020
OK Ardash, here's the Full Demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in color demo image.
folder = pwd;
baseFileName = 'hand palm up.png';
baseFileName = 'hand palm down.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = rgb2gray(grayImage);
end
% Display the original color image.
subplot(2, 3, 1);
imshow(grayImage);
axis on;
caption = sprintf('Original Image : %s', baseFileName);
title(caption, 'FontSize', fontSize);
impixelinfo;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.1, 1, 0.9]);
subplot(2, 3, 2);
imhist(grayImage);
grid on;
title('Histogram of Gray Scale Image', 'FontSize', fontSize);
% Get the binaryImage
% mask = imbinarize(grayImage);
mask = grayImage > 85; % or whatever value works to get the hand.
% Take largest blob only.
mask = bwareafilt(mask, 1);
% Fill any holes.
mask = imfill(mask, 'holes');
% Display the image.
subplot(2, 3, 3);
imshow(mask);
axis on;
title('Mask Image', 'FontSize', fontSize);
% Get bounding box.
props = regionprops(mask, 'BoundingBox');
xLeft = props.BoundingBox(1)
xRight = xLeft + props.BoundingBox(3)
hold on;
rectangle('Position', props.BoundingBox, 'EdgeColor', 'y', 'LineWidth', 2)
% Determine if the hand is a right or left hand.
topHalf = mask;
[rows, columns] = size(mask);
yMiddle = floor(rows/2)+1;
yline(yMiddle, 'Color', 'r', 'LineWidth', 2);
topHalf(yMiddle:end, :) = false; % Erase bottom half.
bottomHalf = mask;
bottomHalf(1:yMiddle, :) = false; % Erase top half.
% Display the images.
subplot(2, 3, 4);
imshow(topHalf);
axis on;
title('Top Half Mask Image', 'FontSize', fontSize);
subplot(2, 3, 5);
imshow(bottomHalf);
axis on;
title('Bottom Half Mask Image', 'FontSize', fontSize);
% Find centroids.
propsTop = regionprops(topHalf, 'Centroid');
propsBottom = regionprops(bottomHalf, 'Centroid');
% Plot Centroids:
subplot(2, 3, 4);
hold on;
plot(propsTop.Centroid(1,1), propsTop.Centroid(1,2), 'r+', 'LineWidth', 2, 'MarkerSize', 20);
subplot(2, 3, 5);
hold on;
plot(propsBottom.Centroid(1,1), propsBottom.Centroid(1,2), 'r+', 'LineWidth', 2, 'MarkerSize', 20);
if propsTop.Centroid(1,1) < propsBottom.Centroid(1,1)
% Forearm is on the right.
xMiddleFinger = ceil(xLeft); % Middle finger is on the left.
caption = sprintf('Palm up hand with middle finger at %d pixels', xMiddleFinger);
else
% Forarm is on the left
xMiddleFinger = floor(xRight); % Middle finger is on the right.
caption = sprintf('Palm down hand with middle finger at %d pixels', xMiddleFinger);
end
% Display middle fingertip and bounding box over original image.
subplot(2, 3, 6);
imshow(grayImage);
axis on;
title(caption, 'FontSize', fontSize);
hold on;
rectangle('Position', props.BoundingBox, 'EdgeColor', 'y', 'LineWidth', 2)
xline(xMiddleFinger, 'Color', 'r', 'LineWidth', 2);
  1 Comment
Adarsh Ankur
Adarsh Ankur on 1 Nov 2020
Sir,can you please mail me this with outputs.
adarshankur1998@gmail.com

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!