Python/Pyside:创建图像直方图

2024-09-29 17:18:38 发布

您现在位置:Python中文网/ 问答频道 /正文

在PySide中创建图像(QImage)直方图最有效的方法是什么?在

我的测试图像1,9MB,3648x2736px,jpeg照片

我试了两种方法:

1。在

import time
start = time.time()

for y in range(h):
    line = img.scanLine(y)  # img - instance of QImage
    for x in range(w):
        color = struct.unpack('I', line[x*4:x*4+4])[0]
        self.obrhis[0][QtGui.qRed(color)] += 1    # red
        self.obrhis[1][QtGui.qGreen(color)] += 1  # green
        self.obrhis[2][QtGui.qBlue(color)] += 1   # blue

print 'time: ', time.time() - start

平均时间=15s

2。在

^{pr2}$

平均时间=4s

更好,但仍然缓慢。 有没有一种更快的方法从QImage计算图像直方图?在


Tags: 方法in图像selfimgfortimeline

热门问题