How to make equal number of images in each class.? which is the best method for this.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Image Analyst
2018-6-22
Try randsample() or randperm() to get the indexes of images to use.
3 个评论
Image Analyst
2018-6-23
编辑:Image Analyst
2018-6-23
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!