clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 20;
storedStructure = load('binaryimage.mat');
binaryImage = storedStructure.BWfinal;
subplot(2, 2, 1);
imshow(binaryImage, []);
title('Original Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
binaryImage(1,:) = true;
binaryImage(end,:) = true;
binaryImage = imfill(binaryImage, 'holes');
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Original Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
binaryImage(1,:) = false;
binaryImage(end,:) = false;
edtImage = bwdist(~binaryImage);
subplot(2, 2, 3);
imshow(edtImage, []);
title('Distance Transform Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
skelImage = bwmorph(binaryImage, 'skel', inf);
skelImage = bwmorph(skelImage, 'spur', 40);
[labeledImage, numLines] = bwlabel(skelImage);
fprintf('Found %d lines\n', numLines);
subplot(2, 2, 4);
imshow(skelImage, []);
title('Skeleton Image', 'FontSize', fontSize, 'Interpreter', 'None');
meanRadius = mean(edtImage(skelImage))
meanDiameter = 2 * meanRadius
message = sprintf('Mean Radius = %.1f pixels.\nMean Diameter = %.1f pixels',...
meanRadius, meanDiameter);
uiwait(helpdlg(message));
Best Answer