grayImage = imread('coins.png');
subplot(2, 2, 1);
imshow(grayImage);
subplot(2, 2, 2);
histogram(grayImage)
binaryImage = imfill(grayImage > 90, 'holes');
binaryImage = bwareafilt(binaryImage, 10);
subplot(2, 2, 3);
imshow(binaryImage);
subplot(2, 2, 4);
[labeledImage, numBlobs] = bwlabel(binaryImage);
props = regionprops(labeledImage, grayImage, 'PixelValues', 'PixelList')
for k = 1 : numBlobs
thisBlobsMin = min(props(k).PixelValues);
mask = ismember(labeledImage, k);
maskedImage = grayImage .* uint8(mask);
[rows, columns] = find(maskedImage == thisBlobsMin);
imshow(maskedImage);
axis('on', 'image');
hold on;
plot(columns, rows, 'r+', 'LineWidth', 2, 'MarkerSize', 15);
hold off
caption = sprintf('Showing cross at %d mins for blob #%d of %d.\n', ...
length(rows), k, numBlobs);
title(caption, 'FontSize', 12);
fprintf('%s\n', caption);
end
fprintf('Done!\n');
Best Answer