获取wand

时间:2016-04-08 22:56:47

标签: python image rgb wand magickwand

我想知道是否可以使用wand计算平均rgb值?

我知道如何使用PIL,但在魔杖的文档中,我无法真正找到如何获取图像数据。

我唯一能找到的是:

for row in image:
    for col in row:
        assert isinstance(col, wand.color.Color)
        print(col)

但是col是一个Color对象,我不确定如何从那里提取值。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您似乎已经使用您提供的信息回答了问题:D

如果colColor对象,那么就像从子节点中提取信息一样简单:

col.red

这是我的完整代码(使用Python 2)。我从来没用过魔杖,但这绝对是棒极了!

from wand.image import Image
from wand.display import display
from wand.color import Color

with Image(filename='mona-lisa.png') as image:
    for row in image:
        for col in row:
            assert isinstance(col, Color)
            print str(col) + "R:"+str(col.red)+"|"+"G:"+str(col.green)+"|"+"B:"+str(col.blue)

所以,如果你想要平均值,你可以将红色,绿色或所有红色平均。

有关Color对象的节点/模块的更多信息,请访问:

Wand Documentation for Color object

相关问题