4
A
回答
3
我已經使用類似下面的幾次來分析圖:
>>> from PIL import Image
>>> im = Image.open('polar-bear-cub.jpg')
>>> from collections import defaultdict
>>> by_color = defaultdict(int)
>>> for pixel in im.getdata():
... by_color[pixel] += 1
>>> by_color
defaultdict(<type 'int'>, {(11, 24, 41): 8, (53, 52, 58): 8, (142, 147, 117): 1, (121, 111, 119): 1, (234, 228, 216): 4
即,有8個像素與RBG值(11,24,41),等等。
21
getcolors方法應該做的伎倆。請參閱the docs。
Image.open('file.jpg').getcolors() => a list of (count, color) tuples or None
6
我想補充一點,.getcolors()函數只適用於圖像處於某種類型的RGB模式。
我有這個問題,它會返回一個元組列表(顏色只是一個數字)的元組列表。花了我一段時間才找到它,但這固定了它。
from PIL import Image
img = Image.open('image.png')
colors = img.convert('RGB').getcolors() #this converts the mode to RGB
0
見https://github.com/fengsp/color-thief-py「抓鬥從圖像中主色或者代表色調色板使用Python和枕頭」
from colorthief import ColorThief
color_thief = ColorThief('/path/to/imagefile')
# get the dominant color
dominant_color = color_thief.get_color(quality=1)
# build a color palette
palette = color_thief.get_palette(color_count=6)
相關問題
- 1. 如何從java中的圖像網格獲取一個圖像?
- 2. 如何從一組圖像中獲取隨機圖像?
- 3. 如何從圖庫中獲取圖像
- 4. 如何獲取圖像的一部分?
- 5. 試圖獲得Magento產品圖像 - 只獲取一個圖像
- 6. 如何從Matlab中修改動態圖像獲取另一個圖像?
- 7. 圖像拖放 - 如何獲取圖像
- 8. 如何獲取圖像clientHeight的圖像?
- 9. 如何取代python中的圖像?
- 10. 獲取python中impaths的圖像名稱
- 11. Python從3d圖像中獲取文本
- 12. 在Python中獲取圖像的值
- 13. 將兩個圖像作爲一個圖像讀取Python
- 14. 如何獲取ooyala圖像?
- 15. 如何獲取geotiff圖像
- 16. 獲取背景圖像中只有一個ng-repeat的圖像
- 17. 如何獲取圖像的URL從拖放如果圖像是一個鏈接?
- 18. Python - 獲取圖像的白色像素
- 19. 如何從Python中的圖像獲取信噪比?
- 20. 如何使用opencv獲取python中的圖像的dct
- 21. 試圖用python獲取圖像
- 22. 如何從圖像獲取SRC jQuery中
- 23. 如何從轉推中獲取圖像?
- 24. 如何從webForm中獲取圖像?
- 25. 如何從php中獲取圖像?
- 26. 如何從Rss中獲取圖像?
- 27. 如何從捲曲中獲取圖像
- 28. 如何從圖像中獲取區域?
- 29. 如何獲取DataGrid中的圖像行?
- 30. 如何從base64encodedstring中獲取圖像?
嘿嘿,我得到一種怪異的結果:它返回(int數組, int)元組..我怎麼能得到r,g,b從一個單一的int? PS:我有一個GIF文件 – nkint 2011-02-27 14:39:05
你可能有一個調色板圖像 - 你可以做im.convert()通過調色板的顏色轉換成一個模式,讓你看到所有的樂隊 – jlivni 2012-07-16 18:55:56
鏈接文檔被打破了。 – 2018-02-13 00:33:09