JPEG / PNG python的颜色直方图

时间:2018-02-15 10:08:44

标签: python image-processing computer-vision python-imaging-library

我试图通过计算颜色直方图来检测图像中的主色。这是图像:

enter image description here

这是我为直方图计算编写的代码:

print(colors)

问题在于,当我说[(588, (255, 255, 255)), (878, (254, 255, 255)), (581, (255, 254, 255)), (209, (254, 254, 255)), (238, (253, 254, 255)), (164, (254, 253, 255)), (380, (253, 253, 255)), (232, (252, 253, 255)), (255, (253, 252, 255)), (16, (252, 252, 255)), (253, (251, 252, 255)), (422, (252, 251, 255)), (14, (251, 251, 255)), (296, (250, 251, 255)), (1515, (251, 250, 255)), (22, (250, 250, 255)), (91, (249, 250, 255)), (2, (247, 250, 255)), (88, (250, 249, 255)), (21, (249, 249, 255)), (1, (246, 249, 255)), (52, (249, 248, 255)), (90, (248, 248, 255)), (5, (245, 248, 255)), (1, (249, 247, 255)), (73, (248, 247, 255)), (245, (247, 247, 255)), (1, (248, 246, 255)), (106, (246, 246, 255)), (3, (242, 246, 255)), (3, (247, 245, 255)), (95, (245, 245, 247)), (39, (244, 245, 247)), (2, (246, 244, 255)),...时,它会输出大量的RGB值及其相应的数量。

SELECT coalesce(SUM( PortFixedIncApp.PrincipalBalance + (PortFixedIncApp.PrincipalBalance * PortFixedIncApp.DailyInterestrate * DATEDIFF(day, PortFixedIncApp.LastDateOfInterestAccruals,'2016-02-05')) + PortFixedIncApp.InterestBalance),0 ) AS MarketValue FROM PortFixedIncApp WHERE (PortFixedIncApp.TransStatus = 'Active') AND PortFixedIncApp.AccountNo='3051010000401' AND (PortFixedIncApp.EndDate <='2016-02-05')

在我看来,JPEG压缩是原因,但我不知道确切的原因。在这种情况下,有人可以帮我计算直方图吗?

1 个答案:

答案 0 :(得分:1)

24 bpp图像的颜色直方图最多有16777216个条目(大多数条目的频率为零)。

我认为将它用于基本上是灰度(甚至是准二进制)的图像是个好主意。

enter image description here

<强>更新

要查找彩色图像中的主色,您可以尝试k-means方法,其中k是您要查找的颜色数。无需使用中间直方图。