簡體   English   中英

在Python中使用PIL分析圖像

[英]Analysis of images using PIL in Python

我發現以下代碼:

import PIL
from PIL import Image
from matplotlib import pyplot as plt

im = Image.open('./color_gradient.png')  
w, h = im.size  
colors = im.getcolors(w*h)

def hexencode(rgb):
 r=rgb[0]
 g=rgb[1]
 b=rgb[2]
 return '#%02x%02x%02x' % (r,g,b)

for idx, c in enumerate(colors):
    plt.bar(idx, c[0], color=hexencode(c[1]),edgecolor=hexencode(c[1]))
plot.show()

有關確切的鏈接,請看這里- 使用matplotlib繪制圖像顏色直方圖

我的問題是軸的含義是什么,如何生成這些值的表格? 我想進行一些統計,例如圖片中綠色或紅色的百分比...

謝謝

PIL文檔中

getcolors

im.getcolors()=>(計數,顏色)元組的列表或無

im.getcolors(maxcolors)=>(數量,顏色)元組的列表或無

所引用圖形中的Y軸是該顏色的像素數,而X軸包括圖形中的(未排序?)顏色列表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM