在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计算图像直方图?在
您可以尝试的另一种方法是将图像数据放入一个numpy数组(希望可能是合理有效的)并使用numpy.histogram。在
相关问题 更多 >
编程相关推荐