how to write multiple images into a folder
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tuffahatul Ummah
le 6 Nov 2016
Réponse apportée : Image Analyst
le 6 Nov 2016
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.
0 commentaires
Réponse acceptée
Geoff Hayes
le 6 Nov 2016
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.
0 commentaires
Plus de réponses (1)
Image Analyst
le 6 Nov 2016
That code is not very robust at all. I can see at least 3 or 4 problems right off the bat. See the FAQ for two ways that it can be done. http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!