clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 20;
folder = 'C:\Users\anand\Documents\Temporary';
baseFileName = 'anand.png';
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
fullFileName = baseFileName;
if ~exist(fullFileName, 'file')
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
[rows, columns, numberOfColorBands] = size(rgbImage);
subplot(2, 2, 1);
imshow(rgbImage);
axis on;
title('Original Color Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
binaryImage = redChannel == 255 & greenChannel == 255 & blueChannel == 0;
subplot(2, 2, 2);
imshow(binaryImage);
axis on;
title('Binary Image', 'FontSize', fontSize);
binaryImage = imdilate(binaryImage, true(3));
binaryImage = imfill(binaryImage, 'holes');
subplot(2, 2, 3);
imshow(binaryImage);
axis on;
title('Filled Binary Image', 'FontSize', fontSize);
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'BoundingBox');
subplot(2, 2, 4);
for k = 1 : numberOfBlobs
thisBB = measurements(k).BoundingBox
thisCroppedImage = imcrop(rgbImage, thisBB);
imshow(thisCroppedImage);
axis on;
caption = sprintf('Region #%d out of %d', k, numberOfBlobs);
title(caption, 'FontSize', fontSize);
promptMessage = sprintf('This is region #%d out of %d.\nDo you want to Continue processing,\nor Cancel to abort processing?',...
k, numberOfBlobs);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
end