I am experimenting with different types of mean subtraction on RGB images for a convolutional neural network. I tried calculating a single grand mean of all the training images. I also tried calculating a mean per color channel. The grand mean I got was 122.84
which sounds like a reasonable number. However, when I tried calculating the means per color channel I got [4.86049, 4.86049, 4.86049]
.
First off, I find it strange that they are all the same number. Secondly, they seem ridiculously low. And thirdly and perhaps most confusingly, shouldn't the mean of the three color channels equal the grand mean?
Maybe it is a problem with my code? This is what I'm using. The images are in a numpy array of the shape (17611, 224, 224, 3)
trainImgsArr = np.random.rand(17611, 224, 224, 3)
grandMean = np.mean(trainImgsArr)
meanByChannel = np.mean(trainImgsArr, axis = (0,1,2))
Any ideas?
EDIT: Ah, ha! I think I have found the true channel means with the code
ch1, ch2, ch3 = np.split(trainImgsArr, 3, axis = 3)
np.mean(ch1)
np.mean(ch2)
np.mean(ch3)
Sorry if this was super basic I am very new to python. Could someone perhaps explain where I went wrong using a single np.mean
call as in the first code bit?
122
's and4.xx
' at the first place?numpy.random.rand
generates values between0
and1
. Is it not the case in your problem? $\endgroup$