【问题标题】:getting the average rgb value of an image in wand在 wand 中获取图像的平均 rgb 值
【发布时间】:2016-04-08 22:56:46
【问题描述】:

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

我知道如何使用 PIL 进行操作,但在 wand 文档中我无法真正找到如何获取图像数据。

我唯一能找到的是这个:

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

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

有什么想法吗?

【问题讨论】:

    标签: python image rgb wand magickwand


    【解决方案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)
    

    因此,如果您想要平均值,您可以将红色的平均值、绿色的平均值或全部平均值。

    更多关于颜色对象的节点/模块可以在这里找到:

    Wand Documentation for Color object

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 2014-04-24
      • 2021-04-04
      • 1970-01-01
      • 2017-08-22
      相关资源
      最近更新 更多