baseFileName = 'SB1.jpg';
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));
rgbImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(rgbImage)
caption = sprintf('Original RGB Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
g2.WindowState = "maximized";
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
[mask, maskedRGBImage] = createMask(rgbImage);
mask = bwareaopen(mask, 5000);
caption = sprintf('Mask Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
props = regionprops(mask, 'BoundingBox', 'Area');
allAreas = sort([props.Area])
allBB = vertcat(props.BoundingBox);
caption = sprintf('Original RGB Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
rectangle('Position', thisBB, 'EdgeColor', 'r')
text(xt, yt, num2str(k), 'Color', 'r', 'FontSize', 17, 'FontWeight','bold', 'VerticalAlignment','bottom');
numRows = ceil(sqrt(numel(props)));
thisBlob = imcrop(rgbImage, thisBB);
subplot(numRows, numRows, k)
caption = sprintf('Seed #%d', k);
function [BW, maskedRGBImage] = createMask(RGB)
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) &...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) &...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;