measure the length in the image

20 ビュー (過去 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 Center および File ExchangeExplore and Edit Images with Image Viewer App についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by