numpy:图像中颜色的唯一列表 [英] numpy: unique list of colors in the image
本文介绍了numpy:图像中颜色的唯一列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张图片img
:
>>> img.shape
(200, 200, 3)
在像素(100,100)上,我的颜色很好:
On pixel (100, 100) I have a nice color:
>>> img[100,100]
array([ 0.90980393, 0.27450982, 0.27450982], dtype=float32)
现在我的问题是:这张图片中有多少种不同的颜色,我该如何枚举它们?
Now my question is: How many different colors are there in this image, and how do I enumerate them?
我的第一个想法是numpy.unique()
,但是我不知何故使用了这个错误.
My first idea was numpy.unique()
, but somehow I am using this wrong.
推荐答案
您可以执行以下操作:
set( tuple(v) for m2d in img for v in m2d )
这篇关于numpy:图像中颜色的唯一列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文