inputFolder = fullfile(pwd, 'Project\Matlab Folder\BMP Data');
filePattern = fullfile(inputFolder, '*.bmp')
bmpFiles = dir(filePattern)
outputFolder = fullfile(pwd, 'Project\Matlab Folder\JPEG Data')
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
figure;
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
for k = 1 : length(bmpFiles)
baseFileName = bmpFiles(k).name;
fullFileNameInput = fullfile(inputFolder, baseFileName)
rgbImage = imread(fullFileNameInput);
subplot(1, 2, 1);
imshow(rgbImage);
title('Original image', 'FontSize', 30);
drawnow;
fullFileNameOutput = fullfile(outputFolder, baseFileName);
fullFileNameOutput = strrep(lower(fullFileNameOutput), '.bmp', 'jpg')
imwrite(rgbImage,fullFileNameOutput);
rgbImage = imread(fullFileNameOutput);
subplot(1, 2, 2);
imshow(rgbImage);
title('Recalled JPG image', 'FontSize', 30);
drawnow;
pause(1);
end
winopen(outputFolder);
Best Answer