fprintf('Beginning to run %s.m ...\n', mfilename);
baseFileName = 'kiwis.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 Image : "%s"', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hFig1.Units = 'Normalized';
hFig1.WindowState = 'maximized';
hFig1.Name = 'Demo by Image Analyst';
[mask, maskedRGBImage] = createMask(rgbImage);
title('Initial Color Segmentation Mask', 'FontSize', fontSize, 'Interpreter', 'None');
imshow(maskedRGBImage, []);
title('Initial Color Segmentation Mask', 'FontSize', fontSize, 'Interpreter', 'None');
leaves = bsxfun(@times, rgbImage, cast(~mask, 'like', rgbImage));
title('Leaves and Sky', 'FontSize', fontSize, 'Interpreter', 'None');
fprintf('Done running %s.m\n', mfilename);
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;