how to find the length of the foot automatically from the image

조회 수: 1 (최근 30일)
Manaswini
Manaswini 2022년 12월 14일
답변: Image Analyst 2022년 12월 14일
i would like to fine the gait parameters(foot length,foot width) from the given image

답변 (2개)

prasanth s
prasanth s 2022년 12월 14일
refer
https://in.mathworks.com/help/images/ref/regionprops.html

Image Analyst
Image Analyst 2022년 12월 14일
Try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'foot.JPEG';
folder = pwd;
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
%=======================================================================================
% Read in image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Display image.
subplot(2, 2, 1);
imshow(rgbImage, []);
impixelinfo;
axis on;
caption = sprintf('Original RGB Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
g = gcf;
g.WindowState = "maximized";
% 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')
drawnow;
%=========================================================================================================================
% Threshold the image to create a mask of the objects
[mask,maskedRGBImage] = createMask(rgbImage);
% Get rid of particles less than 1000 pixels.
props = regionprops(mask, 'Area'); % Measure areas of our initial mask to determine areas of LED and possible noise.
allAreas = sort([props.Area])
mask = bwareaopen(mask, 1000);
% Fill any holes in the blobs.
mask = imfill(mask, 'holes');
% Display the mask image.
subplot(2, 2, 2);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Mask Image', 'FontSize', fontSize);
drawnow;
% Get a mask that is the convex hull of everything.
mask = bwconvhull(mask, "union")
% Display the mask image.
subplot(2, 2, 3);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Mask Convex Hull', 'FontSize', fontSize);
drawnow;
%=========================================================================================================================
% Get the feret diameter.
f = bwferet(mask)
mainAxisCoordinates = f.MaxCoordinates{1}
% Draw a line from one end to the other.
x1 = mainAxisCoordinates(1, 1);
y1 = mainAxisCoordinates(1, 2);
x2 = mainAxisCoordinates(2, 1);
y2 = mainAxisCoordinates(2, 2);
hold on;
line([x1, x2], [y1, y2], 'LineWidth', 2, 'Color', 'r')
% Get the bounding box height.
props = regionprops(mask, 'BoundingBox');
bbHeight = props.BoundingBox(1, 4);
rectangle('Position', props.BoundingBox, 'LineWidth', 2, 'EdgeColor', 'y')
hold off;
message = sprintf('The feret diameter is %.1f pixels.\nThe bounding box height is %d pixels', ...
f.MaxDiameter, bbHeight);
fprintf('%s\n', message);
caption = sprintf('Mask Convex Hull.\n%s', message);
title(caption, 'FontSize', fontSize);
uiwait(helpdlg(message));
%=========================================================================================================================
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 14-Dec-2022
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.682;
channel1Max = 0.214;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.236;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.590;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = ( (I(:,:,1) >= channel1Min) | (I(:,:,1) <= channel1Max) ) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end
Look at the bwferet output to get the width. I didn't do that for you.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by