clc;
close all;
clear;
workspace;
format short g;
format compact;
fontSize = 25;
baseFileName = 'depth6.png';
folder = pwd
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
fullFileNameOnSearchPath = baseFileName;
if ~exist(fullFileNameOnSearchPath, 'file')
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
grayImage = grayImage(:, :, 2);
end
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
caption = sprintf('Original Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
binaryImage = grayImage > 45000 & grayImage < 50000;
binaryImage = imfill(binaryImage, 'holes');
binaryImage = bwareafilt(binaryImage, 1);
subplot(2, 2, 2);
histogram(grayImage);
title('Histogram of depth image', 'FontSize', fontSize);
grid on;
subplot(2, 2, 3);
imshow(binaryImage, []);
axis on;
caption = sprintf('Binary Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo();
drawnow;
props = regionprops(binaryImage, 'BoundingBox');
yTop = props.BoundingBox(2)
xLeft = props.BoundingBox(1)
width = props.BoundingBox(3);
height = props.BoundingBox(4);
yBottom = round(yTop + height/2);
binaryImage(yBottom:end, :) = false;
subplot(2, 2, 4);
imshow(binaryImage, []);
axis on;
caption = sprintf('Binary Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
props = regionprops(binaryImage, 'BoundingBox');
boundingBox = props.BoundingBox
yTop = boundingBox(2)
xLeft = boundingBox(1)
shoulderWidth = boundingBox(3)
height = boundingBox(4)
rectangle('Position', round(boundingBox), 'EdgeColor', 'r', 'LineWidth', 2);
message = sprintf('The shoulder width = %d', shoulderWidth);
title(message, 'FontSize', fontSize, 'Interpreter', 'None');
uiwait(helpdlg(message));
Best Answer