Im using the code below to convert .bmp images to .jpeg, Once typed into the command window no errors appear. However there are no new images written into the 'JPEG Data' folder, Can anyone help?
%load images from file
filePathIn = '.\Project\Matlab Folder\BMP Data'; filePathOut = '.\Project\Matlab Folder\JPEG Data'; %Load names of .bmp files in folder filePathIn
d = dir([filePathIn,'*.bmp']); %for each .bmp file in the directory, convert to jpg
for i = 1:length(d) %read .bmp file
fname = d(i).name; %BMP = imread([filePathIn,d(i).name]);
BMP = imread([filePathIn,fname]); %convert to jpg and rename with .jpg extension
fname = [fname(1:end-4),'.jpg']; imwrite(BMP,[filePathIn,fname],'jpg'); %reload this file in .jpg format
A = imread([filePathIn,fname]); rgbImage = repmat(A,[1 1 3]); %write jpg image to new folder
imwrite(rgbImage,[filePathOut,fname],'JPEG','Quality',100); end
Best Answer