measure the length in the image

조회 수: 9 (최근 30일)
Turbulence Analysis
Turbulence Analysis 2023년 12월 21일
댓글: Turbulence Analysis 2023년 12월 21일
Hi,
How to measure the length of the continous portion of the object shown in the image?

채택된 답변

Image Analyst
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)
rows = 931
columns = 248
numberOfColorChannels = 3
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)
message = 'The height is 818 pixels'
title(message, 'FontSize', fontSize, 'Interpreter', 'None');
  댓글 수: 1
Turbulence Analysis
Turbulence Analysis 2023년 12월 21일
Great!, Thank you very much!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Biomedical Imaging에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by