How to join or merge two Image Data Stores?
이전 댓글 표시
If I have two image datastores and I wish to concatenate them. How can I do that?
Thanks
댓글 수: 1
Sherin Aly
2018년 1월 13일
편집: Sherin Aly
2018년 1월 13일
It was a bit tricky but I was able to merge 2 datastores as follows:
imds1 = imageDatastore(location of DS 1,'IncludeSubfolders',true,'LabelSource','foldernames');
imds2 = imageDatastore(imds2 location,'IncludeSubfolders',true,'LabelSource','foldernames');
% create a dummy dataset with the same size of the combined datastores (if ds1 has 100 images and ds2 has 100 images then dummy has 200 images. I made a folder with some photos with equal number of the 2 datastores)
dummy = imageDatastore('Dummy data store locaation','IncludeSubfolders',true,'LabelSource','foldernames');
% note: below this line you can use any datastore variable you want to merge including the ones you get after splitting training and testing
dummy.Files=[imds1.Files;imds2.Files];
dummy.Labels=[imds1.Labels;imds2.Labels];
% Now dummy is the new combined datastore and you can use all datastore functions
채택된 답변
추가 답변 (6개)
Hana
2018년 1월 18일
I met the same problem and saw your post. Finally I find out a way:
imds = imageDatastore(cat(1,imds1.Files,imds2.Files))
imds.Labels = cat(1,imds1.Labels,imds2.Labels)
It works for me.
댓글 수: 5
Yifan Dong
2018년 9월 18일
Brilliant!! Thanks!
Heng Zhang
2020년 7월 5일
OMG! Thanks bro! That really helps!
Yingying Pang
2021년 3월 6일
brilliant!!!!!
Silvia Guatelli
2021년 3월 19일
Excelente!!! Muchas gracias!
Joseph Garrett
2022년 1월 9일
perfect. thank you so much!!
berkan
2017년 5월 22일
1 개 추천
allImages.Files=[test1.Files;test2.Files]; allImages.Labels=[test1.Labels;test2.Labels];
댓글 수: 1
Sascha D. Krauß
2017년 7월 3일
Unfortunately, this produces a struct instead of a new datastore - and I could not find a way to convert it back. This means, that you cannot use the datastore specific functions like "countEachLabel" etc. Does anyone know another solution?
Birju Patel
2025년 10월 30일
1 개 추천
The best way to do this is to use the datastore combine method:
ds = combine(imds1, imds2, ReadOrder="sequential")
The resulting datastore is a "vertical concatenation" of the two datastores.
KSSV
2017년 2월 27일
A = imread('ngc6543a.jpg');
B = imread('peppers.png');
%%resize the images so that they have same dimensions
A_resize = imresize(A,[size(B,1) size(B,2)]) ;
%%join them
AB = [A_resize B] ;
imshow(AB) ;
댓글 수: 1
kowshik Thopalli
2017년 2월 27일
편집: kowshik Thopalli
2017년 2월 27일
Aasim Khurshid
2020년 12월 30일
편집: Matt J
2022년 6월 28일
There is a better way to do this,
imds = imageDatastore({fullfile(imgFolder1Adress),fullfile(imgFolder2Adress),fullfile(imgFolder3Adress)},...
'IncludeSubfolders',true,'FileExtensions','.png','LabelSource','foldernames');
Perhaps by wrapping them in a TransformedDataStore (R2019a and higher),
imdsnew = transform(imds1,imds2, @(x) x)
카테고리
도움말 센터 및 File Exchange에서 Semantic Segmentation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!