How to process multiple images and produce output files?

H
Hotchin · Jan 10, 2022 · 2K views
Question
I have a sequence of images I am trying to process through the following code and then produce a jpg of the image once it has been processed. There are approximatley 100 images in the folder, named sequentially, so an automatic process/loop is required, any help would be appreciated!    I = imread('Test_3(10fps)-1.jpg'); I = rgb2gray(I); I2 = uint8(filter2(fspecial('gaussian'), I)); J = imread('Test_3(background)-1.jpg'); J2 = uint8(filter2(fspecial('gaussian'), J)); K = imabsdiff(I2,J2); K2 = imadjust(K,stretchlim(K),[0.05,0.5]); imwrite(K2,'image_1')  
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 12, 2026
   %code
   % Save all images name in a sequence manner before doing the operation
   path_directory='folder_name'; % 'Folder name' Must be in current directory
   original_files=dir([path_directory '/*.jpg']); 
   for k=1:length(original_files)
      filename=[path_directory '/' original_files(k).name];
      I=imread(filename)
      I=rgb2gray(I);
      I2=uint8(filter2(fspecial('gaussian'), I));
      J=imread('Test_3(background)-1.jpg');
      J2=uint8(filter2(fspecial('gaussian'), J));
      K=imabsdiff(I2,J2);
      K2=imadjust(K,stretchlim(K),[0.05,0.5]);
      destination='D:\......\folder_name\im'; %Complete path to save image
      %save images as im1.webp, im2.jpg etc
      imwrite(K2,[destination,num2str(k),'.jpg']);
  end

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!