我正在用 Python 实现基本的全局阈值。该算法的一部分涉及根据像素的强度将像素分组到两个容器中;
group_1 = []
group_2 = []
for intensity in list(image.getdata()):
if intensity > threshold:
group_1.append[]
else:
group_2.append[]
对于超过 0.5 兆像素的图像,这种方法通常使用大约 5 秒或更长时间。在每种可能的方法中,我都需要检查每个像素,所以我想知道是否有更快的方法来做到这一点(通过使用 PIL 中的其他方法、其他数据结构或算法?),还是仅仅是 Python 性能问题?