function pushbutton3_Callback(hObject, eventdata, handles)
save_folder_name = uigetdir;
handles.outDir = save_folder_name;
guidata(hObject,handles);
function pushbutton1_Callback(hObject, eventdata, handles)
outDir = handles.outDir;
inDir = handles.inDir;
myFolder=handles.inDir;
filePattern=fullfile(inDir, '*.JPG');
theFiles=dir(filePattern);
caListBoxItems = cell(length(theFiles), 1);
h=waitbar(0, 'Please Wait...');
for k=1:length(theFiles)
RGB = imread(fullfile(inDir, theFiles(k).name));
perc = numel(theFiles);
newRGB = imcrop(RGB,[handles.xMin handles.yMin handles.xMax-handles.xMin handles.yMax-handles.yMin]);
I = rgb2hsv(newRGB);
channel1Min = 0.053;
channel1Max = 0.083;
channel2Min = 0.116;
channel2Max = 0.130;
channel3Min = 0.608;
channel3Max = 0.643;
BW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = ~BW;
maskedRGBImage = RGB;
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
pathname = outDir;
imwrite(BW,[pathname, 'BW', num2str(k), '.jpg'], outDir);
waitbar(k/perc, h);
drawnow;
end
delete(h);