copying multiple images from one folder to other folder

Dear Matlab Users ,
I have 10 folders contain images in the following folder ( " D:\ second_folders ") , inside this folder there are 10 folders names ( folder1 , folder2 ..... , folder10 ) , i need to read each image in each folder and copy the image to another main folder ("D:\ master_folder" ) if its satisfy conditions and put it that copied image in same folder name that it comes from .. for example if image1 was read from folder1 in D:\ second_ folder and satisfy conditions then copied to folder1 in D:\ master_folder and so on for others images in folders ,,,
conditions are :
image type must be .jpg or .png type ,
image size must be >=50 KB ,
thanks ..

댓글 수: 2

Jan
Jan 2016년 1월 27일
편집: Jan 2016년 1월 27일
What have you tried so far and which problems occurred?
What does this mean: "image dimension must be appropriate like Width=600 and hight=100 not accepted" ??
I have solve the last condition , but how to read sequence image , find extension of that image is it jpg or png then find it size if satisfy then create folder in the destination folder and copy that image to it .

댓글을 달려면 로그인하십시오.

 채택된 답변

Stalin Samuel
Stalin Samuel 2016년 1월 27일
편집: Stalin Samuel 2016년 1월 27일
clear all
clc
M_dir = 'D:\ second_folders'% source directory
D_dir = 'D:\ master_folder'
files = dir(M_dir);% main directory
dirFlags = [files.isdir];
subFolders = files(dirFlags);%list of folders
for k = 1 :length(subFolders)
if any(isletter(subFolders(k).name))
c_dtry = strcat(M_dir,subFolders(k).name)
fileList = getAllFiles(c_dtry)%list of files in subfolder
for n1 = 1:length(fileList)
[pathstr,name,ext] = fileparts(fileList{n1})% file type
s = dir(fileList{n1});
S = s.bytes/1000;%file size
Im = imread(fileList{n1});
[h,w,d] = size(Im);%height width and dimension
if ((strcmp(ext,'.jpg')|strcmp(ext,'.png'))&S>=50&(write image dimension condition))% here you need to modify
baseFileName = strcat(name,ext);
fullFileName = fullfile(D_dir, baseFileName); % No need to worry about slashes now!
imwrite(Im, fullFileName);
end
end
end
end

댓글 수: 7

thank you for your code .. i got the following error :
Index exceeds matrix dimensions.
please help >>>
line no??
there are no line following : all screen shoot info
M_dir =
D:\ second_folders
D_dir =
D:\ master_folder
Index exceeds matrix dimensions.
work space screen
files <0x1 struct>
k 1 min 1 max 1
subFolders <0x0 struct>
ok now there are no errors but does not work ..
verify directory paths in your pc with 'M_dir' and 'D_dir'
ahmed obaid
ahmed obaid 2016년 1월 27일
편집: ahmed obaid 2016년 1월 27일
sir i have verify directory path , add your function to matlab path , but dirFlags [] is still empty i think its not able to read subdirectory folders , and K= [] and subfolders is struct 0x0 struct ??
I also have a txt files in the folder. How can I ignore the txt files from being copied and moved. Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품

질문:

2016년 1월 27일

댓글:

2017년 10월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by