How to make equal number of images in each class.? which is the best method for this.
1 view (last 30 days)
Show older comments
Say i have different classes of images, but they are not equal in number to train. some class of images are in 1000's, some are in 100's, some are below 50 and 10. How i can make them equal.? Which is the best method for this.After that i need to do feature extraction. So if i have good number of images in each class i can train well i guess.
6 Comments
Answers (1)
Image Analyst
on 22 Jun 2018
Try randsample() or randperm() to get the indexes of images to use.
3 Comments
Image Analyst
on 23 Jun 2018
Edited: Image Analyst
on 23 Jun 2018
Of course it works. If you get directory listings of all the files of the various classes, and you wanted, say, 50 files of each class, you could get their indexes like this
class1 = dir('class1*.png'); % Get listing of all class 1 images.
class2 = dir('class2*.png'); % Get listing of all class 2 images.
numImagesToExtract = 50;
randomClass1Indexes = randperm(length(class1), numImagesToExtract);
randomClass2Indexes = randperm(length(class2), numImagesToExtract);
Now you have the indexes of the class* variables to use. Just use those indexes to get the filenames of the randomly chosen files to use. What did you do differently?
By the way, you did not make your question clear now. Saying "some class of images are in 1000's" is completely vague. This could mean "some classes have 1000's of images", or "in some classes, the feature values we extract have value in the 1000 to 10 thousand range" or any number of other interpretations. I have no idea what you intend, but my code extracts the same number of randomly-chosen image files from variables having file names in the different classes.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!