clc;
close all;
workspace;
format long g;
format compact;
fontSize = 18;
folder = pwd;
baseFileName = 'index.png';
fullFileName = fullfile(folder, baseFileName)
if ~exist(fullFileName, 'file')
fullFileNameOnSearchPath = baseFileName;
if ~exist(fullFileNameOnSearchPath, 'file')
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(rgbImage)
if numberOfColorChannels > 1
grayImage = rgbImage(:, :, 3);
else
grayImage = rgbImage;
end
subplot(1, 2, 1);
imshow(grayImage, []);
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis('on', 'image');
hp = impixelinfo();
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
mask = grayImage == 255;
mask = bwareaopen(mask, 100);
subplot(1, 2, 2);
imshow(mask);
hp = impixelinfo();
axis('on', 'image');
title('Mask', 'FontSize', fontSize);
props = regionprops(mask, 'Centroid', 'Area');
allCentroids = vertcat(props.Centroid)
hold on;
plot(allCentroids(:, 1), allCentroids(:, 2), 'r+', 'MarkerSize', 30, 'LineWidth', 2);