format longg;
format compact;
clc;
workspace;
fontSize = 25;
folder = 'C:\Users\Naresh\Documents\Temporary';
baseFileName = 'imfill.jpg';
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
fullFileName = baseFileName;
if ~exist(fullFileName, 'file')
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
[rows columns numberOfColorBands] = size(grayImage)
subplot(2, 2, 1);
imshow(grayImage, []);
axis square;
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
binaryImage = grayImage < 128;
subplot(2, 2, 2);
imshow(binaryImage);
axis square;
title('Binary Image', 'FontSize', fontSize);
subplot(2, 2, 3);
imshow(grayImage, []);
title('Original Grayscale Image with Outlines from bwboundaries()', 'FontSize', fontSize);
axis square;
hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'r-', 'LineWidth', 3);
end
hold off;
Best Answer