How to save a sequence of images into a specific folder

168 vues (au cours des 30 derniers jours)
Tharima Ferdausi
Tharima Ferdausi le 3 Mar 2021
Déplacé(e) : Stephen23 le 14 Fév 2023
Hi,
I made this code for capture multiple images for every second and I wanted to automatically save all my images into a specific folders without directly going to the folder from the directory. 'ImageFolder' show the folder-Image Saving Test that I want to save the images in. However, it does not work and put images in whatever folder is shown in the 'Current Folder' in the directory. I try using save and saveas command but it gave me the same problem. Can someone help me resolve this, please?
ImageFolder ='C:\Users\person\Desktop\ Project\Matlab\Image Saving Test';
for i=1:5 % this loop will take 5 pictures and save them in the Matlab folder
img = snapshot(cam);
file_name = sprintf('Image%d.png', i)% name Image with a sequence of number, ex Image1.png , Image2.png....
fullFileName = fullfile(ImageFolder, file_name);
imwrite(img,file_name,'png') %save the image as a Portable Graphics Format file(png)into the MatLab
pause(1); % pause for one second
imshow(img) % display the image for every second
end
  1 commentaire
Francesco Sgromo
Francesco Sgromo le 13 Fév 2023
Hi,
for sure the imwrite command does not use the fullFileName variable you created or the ImageFolder neither.
In any case, you should make sure the folder exists. In case not you can create it using mkdir command.

Connectez-vous pour commenter.

Réponse acceptée

Tharima Ferdausi
Tharima Ferdausi le 3 Mar 2021
Modifié(e) : Stephen23 le 14 Fév 2023
Thank you!!!! I just rearrange my code and replace my fullFileName and imwrite is it can save all the images into a specific folder without doing it twice in the current Folder.
for k=1:5 % this loop will take 5 pictures and save them in the Matlab folder
img = snapshot(cam);
file_name = sprintf('Image%d.png',k)% name Image with a sequence of number, ex Image1.png , Image2.png....
%save the image as a Portable Graphics Format file(png)into the MatLab
imgName = fullfile(ImageFolder,file_name) ;
imwrite(img,imgName);
imshow(img) % display the image for every second
pause(1); % pause for one second
end

Plus de réponses (1)

KSSV
KSSV le 3 Mar 2021
Déplacé(e) : Stephen23 le 14 Fév 2023
ImageFolder ='C:\Users\person\Desktop\ Project\Matlab\Image Saving Test';
for i=1:5 % this loop will take 5 pictures and save them in the Matlab folder
img = snapshot(cam);
file_name = sprintf('Image%d.png', i)% name Image with a sequence of number, ex Image1.png , Image2.png....
fullFileName = fullfile(ImageFolder, file_name);
imwrite(img,file_name,'png') %save the image as a Portable Graphics Format file(png)into the MatLab
pause(1); % pause for one second
imshow(img) % display the image for every second
imgName = [ImageFolder,'\Image_',num2str(i),'.png'] ;
imwrite(img,imgName) ;
end

Produits


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by