how to create a newfolder and save images in it?

i'm accessing all the images in a folder and processing it. now i wanna save all these images in a new folder. the question is how do i create a new folder and start saving the processed images into the new folder?

 Accepted Answer

You would use mkdir() to create the new directory, and you would use the instructions I gave in your previous Question to save the files to there.
For example,
destdirectory = 'C:\Documents and Settings\Pradeep\Processed';
mkdir(destdirectory); %create the directory
thisimage = 'skidoo023.jpg';
fulldestination = fullfile(destdirectory, thisimage); %name file relative to that directory
imwrite(TheData, fulldestination); %save the file there directory

9 Comments

ohh sorry . you have answered it there i didn't check any how thank you. :D
but the problem is i wanna make the user browse and create a new folder in a specified path given by the user. and all this is going to happen in a GUI. can you help me with this?
uiputfile() can be used to select a new location for a directory. If you are on a system where directories have a special file extension then you could use it in the Filter selection to cut down what is in the box.
In Windows, in the putfile() dialog box, there is an icon that allows the user to create a totally brand new folder. Most users (I think ) know about this.
fulldestination = fullfile(destdirectory, thisimage); %name file relative to that directory
imwrite(TheData, fulldestination); %save the file there directory
Can you say what is TheData here? i have an output image which i want to save in a folder after creating it. I use the following code but it gives an error.
destinationFolder = 'E:\imagefolder';
if ~exist(destinationFolder, 'dir')
mkdir(destinationFolder);
end
imwrite(Image1,destinationFolder ,'Rtest.jpeg');
TheData would be the variable containing the data to write.
I use the following code but it gives an error.
You skipped the fullfile() step. You cannot pass a directory and file name to imwrite() as two separate arguments: you have to construct a complete file name and pass that to imwrite()
imshow(Image1);
S=Image1;
thisImage='Rtest.jpeg';
fulldestination = fullfile(destinationFolder,thisImage); %name file relative to that directory
imwrite(S, fulldestination);
I cannot figure out the mistake in the code. It is still giving an error. Can you please help me with it?
I have figured out the issue, Thanks.

Sign in to comment.

More Answers (0)

Categories

Products

Tags

Community Treasure Hunt

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

Start Hunting!