myFolder = '/Users/masonlien/Desktop/PhD/Drone/2020/test';
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease select another folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir();
end
filePattern = fullfile(myFolder, '*.tif');
theFiles = dir(filePattern);
numFiles = length(theFiles);
if numFiles == 0
warningMessage = sprintf('Warning: no TIFF images found in the folder:\n%s', myFolder);
uiwait(warnuser(warningMessage));
return;
end
for k = 1 : numFiles
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf('Now reading %s (#%d of %d).\n', fullFileName, k, numFiles);
imageArray = imread(mat2gray(fullFileName));
imshow(imageArray);
caption = sprintf('%s (#%d of %d)', fullFileName, k, numFiles);
title(caption, 'FontSize', 14, 'Interpreter', 'none');
drawnow;
baseFileName = strrep(lower(baseFileName), '.tif', '.jpg');
outputFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now writing %s\n', outputFileName);
imwrite(imageArray, outputFileName);
end