为什么 QImage 的像素函数超出范围?

Why does QImage's pixel function goes out of scope?

我有高度 = 394 和宽度 = 700 的图像,换句话说行 = 394 和 col = 700。但是当我尝试通过 grey_img.pixel(row, col) 访问给定像素的像素值时,我超出了范围错误。出于某种原因 grey_img.pixel(col, row) 有效。

谁能帮我弄清楚,为什么我在执行 grey_img.pixel(row, col) 而不是相反时会出现超出范围的错误?

我认为索引会是 (row, col) 因为

(0,0),(0,1),(0,2)...(0,699)

(1,0),(1,1),(1,2)...(1,699)

...

(393,0),(393,1),(393,2)...(393,699)

from PyQt5.QtGui import QImage, qGray

# read jpg image and convert it to grey scale.
grey_img = QImage("test_img.jpg").convertToFormat(QImage.Format_Grayscale8)

# print the pixel value of each pixel form the grey scale image.
img_height = grey_img.height()
img_width = grey_img.width()
print("height = ", img_height)
print("width  = ", img_width)

# height =  394
# width  =  700

for row in range(0, img_height):
    for col in range(0, img_width):
        # works
        gray_val = qGray(grey_img.pixel(col, row))

        # does not work
        # gives out of range error
        # QImage::pixel: coordinate (179,482) out of range
        # gray_val = qGray(grey_img.pixel(row, col))

QImage::pixel 函数将参数 (int x, int y) 作为 (column, row)