How to make equal number of images in each class.? which is the best method for this.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Image Analyst
el 22 de Jun. de 2018
Try randsample() or randperm() to get the indexes of images to use.
3 comentarios
Image Analyst
el 23 de Jun. de 2018
Editada: Image Analyst
el 23 de Jun. de 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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!