measure the length in the image
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi,
How to measure the length of the continous portion of the object shown in the image?
댓글 수: 0
채택된 답변
Image Analyst
2023년 12월 21일
Try this:
% Tests curl for triggering stats analysis of laundry stain removal raw data.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
format compact;
%--------------------------------------------------------------------------------------------------------
% READ IN TEST IMAGE
folder = pwd;
baseFileName = "Image 2.bmp";
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 size
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels == 3
grayImage = grayImage(:,:,1);
end
% Display the image.
subplot(1, 2, 1);
imshow(grayImage);
axis('on', 'image');
impixelinfo;
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Threshold the image.
mask = ~imbinarize(grayImage);
% Take the largest blob
mask = bwareafilt(mask, 1);
% Display the image.
subplot(1, 2, 2);
imshow(mask);
axis('on', 'image');
impixelinfo;
title('Original Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Measure bounding box.
props = regionprops(mask, 'BoundingBox');
bb = props.BoundingBox;
hold on;
rectangle('Position', bb, 'EdgeColor', 'r', 'LineWidth', 2)
theHeight = bb(4);
message = sprintf('The height is %d pixels', theHeight)
title(message, 'FontSize', fontSize, 'Interpreter', 'None');
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Biomedical Imaging에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!