measure diameter starting with a certain point

2 views (last 30 days)
I used the code suggested by @Image Analyst to calculate the shortest distance between the boundaries. Now I need to measure the diameter of the larger blob, but most importantly, I want to start measuring at the same point we measured the shortest distance and plot the diameter as a coloured line over the binary image.
the code i used to measure the shortest distance
% Define object boundaries
numberOfBoundaries = size(binaryImage, 1);
boundary1 = boundaries{1};
boundary2 = boundaries{2};
boundary1x = boundary1(:, 2);
boundary1y = boundary1(:, 1);
x1=1;
y1=1;
x2=1;
y2=1;
overallMinDistance = inf; % Initialize.
index1 = 1;
index2 = 1;
for k = 1 : length(boundary2)
boundary2x = boundary2(k, 2);
boundary2y = boundary2(k, 1);
% For this blob, compute distances from boundaries to edge.
allDistances = sqrt((boundary1x - boundary2x).^2 + (boundary1y - boundary2y).^2);
% Find closest point, min distance.
[minDistance(k), indexOfMin] = min(allDistances);
if minDistance(k) < overallMinDistance
overallMinDistance = minDistance(k);
x1 = boundary1x(indexOfMin);
y1 = boundary1y(indexOfMin);
x2 = boundary2x;
y2 = boundary2y;
index2 = k;
index1 = indexOfMin;
end
end
% Report to command window.
fprintf('narrowest rim length = %f at index %d of boundary 1 and index %d of boundary 2.\n', ...
overallMinDistance, index1, index2);
hFig = figure;
h1 = subplot(1, 1, 1);
imshow(binaryImage);
title('Narrowest rim', 'FontSize', 10);
hFig.WindowState = 'maximized';
hold on;
% Draw a line between point 1 and 2
NarrowestRim=line(h1, [x1, x2], [y1, y2], 'Color', 'y', 'LineWidth', 3);

Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!