measure the length in the image
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Turbulence Analysis
il 21 Dic 2023
Commentato: Turbulence Analysis
il 21 Dic 2023
Hi,
How to measure the length of the continous portion of the object shown in the image?
0 Commenti
Risposta accettata
Image Analyst
il 21 Dic 2023
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');
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Biomedical Imaging in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!