我正在尝试比较(r,g,b)值的两个2d数组元组,其大小分别为[2048] [4096]和[398] [40]。我想在其中找到相等的元组值,每次找到它时,我都想向另一个数组[2048] [4096]添加某个值。下面的代码可以正常工作,但是对于我们拥有的数据量来说,它的速度非常慢。
from PIL import Image
import numpy as np
map = Image.open('ozone.png')
scale = Image.open('scale.png')
rgb_map = map.convert('RGB')
rgb_scale = scale.convert('RGB')
pixeltoDOB = 1.0050251256
scaleVals = []
mapVals = []
for x in range(398):
scaleVals.append([])
for y in range(40):
r, g, b = rgb_scale.getpixel((x, y))
scaleVals[x].append((r,g,b))
for y in range(2048):
mapVals.append([])
for x in range(4096):
r, g, b = rgb_map.getpixel((x,y))
mapVals[y].append((r,g,b))
ozoneVals = np.zeros((2048,4096))
for i in range(128):
for j in range(256):
for k in range(398):
for l in range(40):
print(i,j,k,l)
if (mapVals[i][j]) == (scaleVals[k][l]):
ozoneVals[i][j] = pixeltoDOB * k
print(ozoneVals[2][128]) ##just to see if it works