我正在处理一个脚本,该脚本的工作是梳理包含像素值的CSV文件。我使用了一个json文件来查找预先标注的多边形的尺寸,并且试图计算该对象内平均像素的值。 pixel_temperature列表与图像的尺寸相同[512] [640]。我正在使用skimage的多边形函数来计算多边形点内的所有像素
# Find all points within polygon
r = np.array([y1, y2, y3, y4])
c = np.array([x1, x2, x3, x4])
x_axis, y_axis = draw.polygon(r, c)
注意:我的JSON中的x和y混合在一起,这就是为什么我要先声明y
这将产生两个长度相等的nparrays(x_axis,y_axis)(在选择了随机点的情况下进行了测试,它们也是坐标,因此需要成对出现)我试图同时遍历这两个列表,然后计算出我的值。这适用于我的大多数多边形,但是我随机点击
Traceback (most recent call last):
File "u-valueV2.py", line 232, in <module>
main()
File "u-valueV2.py", line 228, in main
parseJSON(jsonFilePath)
File "u-valueV2.py", line 113, in parseJSON
average_u_value = parseCSVPolygon(csvFilePath, csvFileName[0], x_axis, y_axis)
File "u-valueV2.py", line 197, in parseCSVPolygon
total += u_value_calculation(emissivity, pixel_temperature[x[item]][y[item]])
IndexError: list index out of range
由于列表的长度相等,并且我的pixel_temp列表包含所有512 x 640的值,所以我不明白为什么会收到此错误。
错误是指我parseCSVPolygon函数中的此块
fileName += ".csv"
path = csvFilePath + '/' + fileName
with open(path) as read_csv:
csvData = csv.reader(read_csv, delimiter=',', quotechar='|') # Seperated by comma (hence csv)
for i, data in enumerate(csvData): # i holds the index and increments each loop while data holds cells value
length = len(data)
if (length == 0): # Incase the length of a row is 0 (empty cells)
continue
else:
index = length - 1 # Extract the last data point in the row
if (i == 2):
emissivity = float(data[index])
#print(emissivity)
if (i >= 10):
pixel_temperature.append(data[1:]) # Pixel temperature now holds 512 indexes. Each index
#TODO: Figure out how to calculate the doors u-value (or Polygons)
for item in range(len(y)):
total += u_value_calculation(emissivity, pixel_temperature[x[item]][y[item]])
average = total / (len(x) * len(y))
return average
我对此错误的根源感到困惑。谁能帮我吗?