how to overcome overwrite of the saved images in a folder

hi sir, can I know how to overcome the overwrite file that have been save in a folder? for instance, it can save a 001.jpg image in a file. however, when I run program for another image , it will overwrite 001.jpg as another image. I want the second image save as 002.jpg in a same folder and make it for the next image.. pls advice and help!

Answers (1)

4 Comments

sir, in my case, the cropped image will be write say 40x40 and save as 001.jpg. how to do the image and give as 002.jpg and not get overwritten the first file.
after I used this code myFolder = 'C:\Documents and Settings\yourUserName\My Documents\My Pictures'; if ~isdir(myFolder) errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder); uiwait(warndlg(errorMessage)); return; end filePattern = fullfile(myFolder, '*.jpg'); jpegFiles = dir(filePattern); for k = 1:length(jpegFiles) baseFileName = jpegFiles(k).name; fullFileName = fullfile(myFolder, baseFileName); fprintf(1, 'Now reading %s\n', fullFileName); imageArray = imread(fullFileName); imshow(imageArray); % Display image. drawnow; % Force display to update immediately. end
in the loops to save file in a folder. the save file still overwritten. how can not overwrite the previous image and save the next image consequently
Code given in the FAQ almost always needs to be adapted to fit the individual user's situation. The code in the FAQ just reads images. If you want to write images you need to use a similar concept of using sprintf() to create an output file name, which may be in a different folder or the same folder, and then use imwrite().

Sign in to comment.

Categories

Asked:

on 15 Oct 2012

Community Treasure Hunt

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

Start Hunting!