How to store resize images into new directory?

When I resize single image and store into new directory, it is working properly
filename='E:\img\xyz.jpg';
im = imread('E:\img\xyz.jpg');
k=imresize(im,[300,300]);
imwrite(k,'E:/Resizeimage/aa.jpg','jpg');
But when I resize all images from one directory and try to store into new directory, it is not working properly. I am posting here code. Can anybody tell me what is the problem?
srcFiles = dir('E:\img\*.jpg'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('E:\img\',srcFiles(i).name);
im = imread(filename);
k=imresize(im,[300,300]);
nm= 'E;/Resizeimage/';
nm1='srcFiles(i).name';
strcat(nm,nm1);
imwrite(k,nm,'jpg');
end

6 Comments

Problem is solved.
would u plz tell us how do you have solved the problem as i'm facing same problem in imwrite function As i found the new image folder is empty,
srcFiles = dir('E:\img\*.jpg'); % the folder in which ur images exists for i = 1 : length(srcFiles) filename = strcat('E:\img\',srcFiles(i).name); im = imread(filename); k=imresize(im,[300,300]); newfilename=strcat('E:\img\',srcFiles(i).name); imwrite(k,newfilename,'jpg'); end
thank you it helped me
Thank you, it helped me too!!

Sign in to comment.

 Accepted Answer

anu
anu on 21 Dec 2017
Edited: Walter Roberson on 21 Dec 2017
srcFiles = dir('E:\img\*.jpg'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('E:\img\',srcFiles(i).name);
im = imread(filename);
k=imresize(im,[300,300]);
newfilename=strcat('E:\img\',srcFiles(i).name);
imwrite(k,newfilename,'jpg');
end

6 Comments

thank you.. it was helpful...
what is .name here in the code
@Dibyalekha Nayak .name is a field of the structure srcFiles(i), which is the i'th structure in the array of structures called srcFiles. That field contains the base filename without the folder prepended, like it might be "myimage.jpg". The .folder field contains the folder and in this case, since all the files are in the same folder, srcFiles(i) will be 'E:\img'.
As I am trying to execute this code but i am getting an error like,you may not have read and write permission.
@Dibyalekha Nayak what is your source and destination folders? You cannot rename or copy anything under the c:\Program Files folder in Windows. Also, if one of the source or destination files is open in another program, it may be locked and you may not have permission to do anything in MATLAB with it.
Start your own thread with your script attached.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Sign in to comment.

More Answers (0)

Asked:

anu
on 1 Dec 2016

Commented:

on 13 Dec 2022

Community Treasure Hunt

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

Start Hunting!