Calculate mean value of an image dataset
The mean value of the dataset is the mean value of the pixels of all the images across all the colour channels (e.g. RBG). Grey scale images will have just one mean value and colour images like ImageNet will have 3 mean values. 
Usually mean is calculated on the training set and the same mean is used to normalize both training and test images.
In deep learning experiments,there is a consensus that mean subtraction from the data set could improve the accuracy.For example,the mean value of ImageNet is [104.0 117.0 124.0],so before feeding the network,the mean value will be subtracted from the image. My question is 

How the mean value is calculated?
Should I calculate the mean value on training and testing data set separately?