MATLAB: How to write multiple images into a folder

imwritemkdir

I have this code
[parentFolder deepestFolder] = fileparts('24x24');
output_folder = 'E:\Bismillah Wisuda 115\progress TA ku new\program';
for a=1:40
im=imread(['E:\Bismillah Wisuda 115\progress TA ku new\program\data training\citra training positif2\kendaraan' num2str(a) '.jpg']);
image=imresize(im,[24 24]);
imwrite(image,['kendaraan' num2str(a) '.jpg'],'jpg');
newSubFolder = sprintf(deepestFolder);
fullname = fullfile(output_folder,'output_folder',newSubFolder);
if ~exist(parentFolder, 'dir')
mkdir(parentFolder);
end
end
it can run, but my folder is still empty. Can you please fix it? Thank you.

Best Answer

Tuffahatul - it isn't clear why there is a command to create a parentFolder. Is this where you intend to put the new images? Or is this intended for something else?
Your don't supply a path as to where you want to write the files when calling imwrite
imwrite(image,['kendaraan' num2str(a) '.jpg'],'jpg');
so I suspect that the files are being copied into some other directory perhaps along the MATLAB search path. If there is a location where you want to write the file to, then you need to be explicit about it. For example,
myImage = imresize(im,[24 24]);
outputFileName = fullfile(output_folder, ['kendaraan' num2str(a) '.jpg']);
imwrite(myImage, outputFileName);
So we resize the image and then create the file name and path where we want to write the resized image to. Note how I have replaced your local variable image with myImage. image is a built-in MATLAB function, so it is never a good idea to name a local variable that has the same name as a built-in function.