"ele"是什么意思以及这段代码在OpenCV中的规则

What does "ele" mean and the rule of this code in OpenCV

该代码用于调整任何图像的对比度和亮度,我不知道cimg[i, j] = [int(ele) if ele < 255 else 255 for ele in lst]是什么意思?尤其是[int(ele) if ele < 255 else 255 for ele in lst],我以前没有见过这些代码规则,请帮助我,谢谢你们!

另一个问题,"ele"是否表示数组中的每个元素?

    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
            lst = 0.1*cnum*img[i, j] + bnum
            cimg[i, j] = [int(ele) if ele < 255 else 255 for ele in lst]

这里,代码包含List Comprehension。这是从可迭代对象创建新列表的简单而干净的方法。

无需使用列表理解即可重写此代码。

for i in range(img.shape[0]):
    for j in range(img.shape[1]):
        lst = 0.1 * cnum * img[i, j] + bnum
        pixel = list()
        for ele in lst:
           if ele < 255:
              pixel.append(int(ele))
           else:
              pixel.append(255)
        cimg[i, j] = pixel

This is a nice tutorial to understand list comprehension