How to select only those image folders containing images more than 100. From a set of 193 image folders.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Karthik K
il 12 Lug 2018
Commentato: Karthik K
il 18 Lug 2018
Here i have 193 folders, where in each folder contains a set of images. In each folder, total number of images are not the same. It is like 15, 28, 64, 96, 125, 265, 456, 564, and so on. Now i need to take only those folders where my images count is more than 100.(out of these 193 folders). Then splitting it into training and testing. How i can do it? I tried this code. but its not working properly. Please help.
SetDir = fullfile('D:\MATLAB\Proj_Work\seperated');
Imds = imageDatastore(SetDir,'IncludeSubfolders',true,'LabelSource','foldernames');
T = countEachLabel(Imds);
minSetCount = 100;%min([T.Count]);
Imds_New = splitEachLabel(Imds,minSetCount,'randomize');
[trainingSet,testSet]=splitEachLabel(Imds_New,0.7,'randomize');
6 Commenti
Jan
il 17 Lug 2018
Modificato: Jan
il 17 Lug 2018
@karthik k: It is clear already, what you want to achieve. There is no need to repeat this explanation. You have posted some code. The open question is, what you observe, when you run it. We want to fix the problem with your code, but you do not mention, what the problem is. All we know yet is: "not able to fetch", "not working" and "not able to have only those folders". Do not describe, what the code doesn't do, but explain, what it does instead. This is the 3rd question for clarification concerning the same point.
I do not have the toolbox to run imageDatastore. It would be easy to write a code with a loop and some dir commands. But this might not match your current workflow.
Risposta accettata
Image Analyst
il 17 Lug 2018
Modificato: Image Analyst
il 17 Lug 2018
karthik, try this:
SetDir = fullfile('D:\MATLAB\Proj_Work\seperated'); % My Main folder path.
imds = imageDatastore(SetDir,'IncludeSubfolders',true,'LabelSource','foldernames'); % All Sub folders with its labels. (193 folders, images in each folder along with its label)
% Get the total number of files in each folder.
T = countEachLabel(imds); % Total count in each folder
% See which folders have at least 100 files in them.
foldersWithEnoughFiles = T.Count >= 100;
% Build a list (cell array) of all the folders.
allFolderList = cell(size(T, 1), 1);
for k = 1 : size(T, 1)
[thisFolder, ~, ~] = fileparts(imds.Files{k});
allFolderList{k} = thisFolder;
end
% Extract only those folders with 100 files or more.
goodFolders = unique(allFolderList(foldersWithEnoughFiles));
% Get a new datastore with only those folders with 100 or more files in them.
imds_good = imageDatastore(goodFolders,'IncludeSubfolders',false,'LabelSource','foldernames'); % All Sub folders with its labels. (193 folders, images in each folder along with its label)
% Split all files into a test set and a training set.
splitPercentage = 0.8;
[imds_train, imds_test] = splitEachLabel(imds_good, splitPercentage, 'randomize');
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!