【发布时间】:2019-07-03 00:48:21
【问题描述】:
我将图像存储在 gray_img_here 中,这是一个二维数组的 python 列表。 我想通过应用来标准化每个图像:X = (X-u)/S 其中 X 是像素值,U 是图像的平均值,S 是该像素的偏差
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
但是我得到了错误: 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:只有 size-1 的数组可以转换为 Python 标量
gray_img_here 看起来像这样
[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],
...,
【问题讨论】:
-
我已经读过了。我想标准化我的数据而不是标准化。
-
你能展示一下数组 gray_img_numpy 的样子吗?
-
我添加了它@EdekiOkoh
-
不是错误本身,但我会查看这一行 gray_img_here[i] = float(gray_img_here[i] - np.mean(gray_img_numpy[i])) / float(np.std(gray_img_numpy [i], axis=0)。我不认为这是在做你认为它在做的事情。你想使用数组中每个数组的平均值,而不是第 i 个元素