简体   繁体   English

我如何在 0 到 26 之间更快地标准化像素

[英]how do i normalize pixels faster between 0 and 26

I have a vector with about 150528 pixels.我有一个大约 150528 像素的向量。

img1 = image.load_img(path = "image.jpg", target_size = (224, 224, 3))

img1_pixel_array = image.img_to_array(img = img1, dtype = np.uint8)

a = img1_pixel_array.reshape(150528,)

I normalizing between 0 and 26 for this data.我将此数据标准化为 0 到 26 之间。

list = []
for i in a:
    z = (i - min(a)) / (max(a) - min(a)) * 26
    list.append(z)

The problem is that only 1000 pixels are processed in 40 seconds.问题是在 40 秒内只处理了 1000 个像素。 My question is how do I normalize this data between 0 and 26 faster.我的问题是如何更快地将这些数据标准化为 0 到 26 之间。

If seems that you are recomputing the minimum (twice) and maximum of a on every iteration.如果您似乎在每次迭代中重新计算a的最小值(两次)和最大值。 This does not sound like a good idea.这听起来不是一个好主意。

You'd better precompute the scaling coefficients A and B such that z = A i + B.您最好预先计算比例系数 A 和 B,使得 z = A i + B。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM