How to save a sequence of images into a specific folder

Illustration
Tharima Ferdausi - 2022-11-22T10:07:50+00:00
Question: How to save a sequence of images into a specific folder

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  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

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.webp', i)% name Image with a sequence of number, ex Image1.webp , Image2.webp....
    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),'.webp'] ;
    imwrite(img,imgName) ; 
end

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!