How to copy 30K images from folder to another according to the names in train and test text listes
이전 댓글 표시
clear,clc;
path = addpath(genpath('D:\DOCTORAT 2019\MATLAB Codes\datasets\NUS-WIDE-OBJECT\image list'));
DIR = 'D:\Dataset\NUSWIDE-Obj\imagesnus30k';%Source file
D_dir = 'D:\Dataset\NUSWIDE-Obj\Images30K';%Destination file (Sould be 31-subfolder=Nbre of classes)
class = {'bear','birds','boats','book','cars','cat','computer','coral','cow','dog','elk','fish','flags','flowers','fox','horses','leaf','plane','rocks','sand','sign','statue','sun','tiger','tower','toy','train','tree','vehicle','whales','zebra'}; %31 classes
tr = textread('Train.txt','%s');
ts = textread('Test.txt','%s');
imgs = vertcat(tr,ts);
for i =1:size(imgs,1)
disp(i)
% img = imread([ DIR,'\\',string(imgs(i,1))]);
imgname = (strcat(DIR, '\',string(imgs(i,1))));
img_files{i} = char(imgname);
fullFileName = fullfile(DIR, imgname);
%imwrite(img,D_dir,'jpg')
% figure(1),imshow(img);
%pause();
% imds = imageDatastore(img_files{i});
% img = readimage(imds,I);
% [img,info] = readimage(imds,2);
end
댓글 수: 3
Jan
2022년 11월 21일
What is your question?
It is a bad design to add folders to Matlab's PATH only to import files. Insert only folder, which contain M-files to the PATH and import files using absolute path names.
The readers can help you, if you explain, why you have commented the part of the code.
riad didou
2022년 11월 21일
채택된 답변
추가 답변 (1개)
Benjamin Thompson
2022년 11월 21일
0 개 추천
Use copyfile to copy a file to a new location. You could probably use arrayfun to more quickly add the full file path to the file names output from the dir function. Or, you could probably pass a function to arrayfun that does the full file path creation and the copyfile all in one.
댓글 수: 2
riad didou
2022년 11월 21일
Benjamin Thompson
2022년 11월 21일
You can type "doc copyfile" and "doc arrayfun" in MATLAB to bring up the documentation and examples of using both functions.
카테고리
도움말 센터 및 File Exchange에서 Images에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

