function pushbutton3_Callback(hObject, eventdata, handles)
Interval=str2num(char(get(handles.edit2,'String')));
if isempty(Interval)
errordlg('Error, please load pictures to be processed and enter a picture time interval before clicking Run.');
else
outDir = handles.outDir;
inDir = handles.inDir;
includeSubdirectories = true;
imreadFormats = imformats;
supportedExtensions = [imreadFormats.ext];
supportedExtensions{end+1} = 'dcm';
supportedExtensions{end+1} = 'ima';
supportedExtensions = strcat('.',supportedExtensions);
supportedExtensions{end+1} = '';
imds = datastore(inDir,...
'IncludeSubfolders', includeSubdirectories,...
'Type','image',...
'FileExtensions',supportedExtensions);
h=waitbar(0, 'Please Wait...');
for imgInd = 1:numel(imds.Files)
perc=numel(imds.Files);
inImageFile = imds.Files{imgInd};
outImageFile = strrep(inImageFile, inDir, outDir);
try
im = imds.readimage(imgInd);
im = trial_3(im);
if(isdicom(inImageFile))
dicommeta = dicominfo(inImageFile);
dicomwrite(im, outImageFile, dicommeta, 'CreateMode', 'copy');
else
imwrite(im, outImageFile);
end
disp(['PASSED:', inImageFile]);
catch allExceptions
disp(['FAILED:', inImageFile]);
disp(getReport(allExceptions,'basic'));
end
waitbar(imgInd/perc, h);
drawnow;
end
delete(h);
myFolder=handles.outDir;
filePattern=fullfile(myFolder, '*.JPG');
theFiles=dir(filePattern);
caListBoxItems = cell(length(theFiles), 1);
for k=1:length(theFiles)
baseFileName=theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
thisString = fprintf(1, 'Now reading %s', fullFileName);
fprintf('%s\n', thisString);
caListBoxItems{k} = thisString;
OutputFileNames{k} = theFiles(k).name;
set(handles.listbox2, 'String', OutputFileNames);
drawnow;
image=imread(fullFileName);
white=nnz(image);
black=(numel(image)-white);
time=((k-1)*Interval);
if black>(numel(image)*0.0193);
disp('The experiment is complete at this stage!')
fprintf('The number of Black Pixels is:');
disp(numel(image)-white);
disp('Time of Picture (Secs): ');
disp((k-1)*Interval);
Status = ('Complete');
else
disp('The experiment is not complete yet.')
fprintf('The number of Black Pixels is:');
disp(numel(image)-white);
Status = ('Incomplete');
end
PhotoDetails={fullFileName, black, time, Status};
Matrix(k,:)=PhotoDetails;
guidata(hObject,handles);
end
end
Header={'Image', 'Number of Black Pixels', 'Time (Seconds)', 'Status'};
xlswrite('PhotoResults', Header, 'Results');
xlRange='A2';
xlswrite('PhotoResults', Matrix, 'Results', xlRange);