I am storing my images in gray_img_here which is a python list of 2d arrays. I want to standardise each image by applying: X = (X-u)/S where X is the pixel value, U is the mean of the image and S is the deviation of that pixel
def normalizeImages(self, gray_img_here):
print "Normalizing the gray images..."
print
gray_img_numpy = np.array(gray_img_here)
for i in range(len(gray_img_here)):
print
# print "mean of the {}th image", np.mean(gray_img_numpy[i])
# print "std dev. of the {}th image", np.std(gray_img_numpy[i])
# print
gray_img_here[i] = float(gray_img_here[i] - np.mean(gray_img_numpy[i])) / float(np.std(gray_img_numpy[i], axis=0))
return gray_img_here
However I get the error : gray_img_here[i] = float(gray_img_here[i] - np.mean(gray_img_numpy[i])) / float(np.std(gray_img_numpy[i], axis=0))
TypeError: only size-1 arrays can be converted to Python scalars
gray_img_here looks like this
[array([[ 37, 39, 41, ..., 119, 113, 109],
[ 38, 40, 41, ..., 119, 113, 109],
[ 39, 41, 42, ..., 117, 112, 108],
...,
[ 25, 25, 26, ..., 168, 180, 182],
[ 25, 26, 26, ..., 179, 191, 189],
[ 26, 26, 26, ..., 184, 196, 191]], dtype=uint8), array([[ 91, 97, 101, ..., 48, 49, 51],
[ 89, 93, 98, ..., 44, 45, 45],
[ 85, 88, 94, ..., 40, 41, 41],
...,
[137, 90, 52, ..., 35, 36, 36],
[163, 103, 68, ..., 35, 35, 35],
[216, 148, 107, ..., 35, 35, 34]], dtype=uint8), array([[ 64, 75, 93, ..., 85, 83, 82],
[ 83, 93, 98, ..., 85, 81, 80],
[ 91, 98, 96, ..., 84, 80, 81],
...,