I have a NumPy array (1513,256,256,1) which actually contains 1513 gray images with size (256,256). Each image contains 4 classes (values are 0,1,2,3). 0 means background. But values are not an integer, they are float 32. I want to count the number of pixels or elements belong to each class. Data in unbalanced so I'm trying to balance it. I tried some methods but they didn't work. One thing is that the numbers are not integer so they belong to several classes, not just 4 classes. Does anyone have any idea how to get the number of elements of each class?
I used this code here, but it didn't work.
y_integers = np.argmax(masks, axis=1)
class_weights = compute_class_weight('balanced', np.unique(y_integers), y_integers)
d_class_weights = dict(enumerate(class_weights))