国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

Python的PIL庫中g(shù)etpixel方法的使用

瀏覽:3日期:2022-07-30 15:05:58

getpixel函數(shù)是用來獲取圖像中某一點的像素的RGB顏色值,getpixel的參數(shù)是一個坐標點。對于圖象的不同的模式,getpixel函數(shù)返回的值有所不同。

1.RGB模式

from PIL import Imageim=Image.open(’d:/22.jpg’)print(im.mode)print(im.getpixel((0,0)))

結(jié)果為

RGB(149, 80, 41)

返回的是坐標點(0,0)處的red,green,blue的數(shù)值

2.P模式

from PIL import Imageim=Image.open(’d:/22.jpg’)im2=im.convert('P')print(im2.mode)print(im2.getpixel((0,0)))

結(jié)果為

P61

可以看到轉(zhuǎn)化為P模式之后,坐標點(0,0)處的值有所變化

3.“1”模式

from PIL import Imageim=Image.open(’d:/22.jpg’)im2=im.convert('1')print(im2.mode)print(im2.getpixel((0,0)))

結(jié)果為

10

之后的模式不再實驗,此處想要說明的是在對圖像進行處理的時候,如果是用Image.open()打開一個圖像,那么該圖像一定會變成RGB模式,如果想要利用getpixel的返回的函數(shù)值,三元組的數(shù)值不太好處理,就可以把圖像模式轉(zhuǎn)變?yōu)椤癙”模式,“L”模式等,方便利用getpixel返回值

示例代碼:

from PIL import Imageimport matplotlib.pyplot as pltimg = Image.open('D:image_for_testSpee.jpg')plt.imshow(img)plt.show()print(img.getpixel((0,0)),img.getpixel((178,298)))

結(jié)果:

Python的PIL庫中g(shù)etpixel方法的使用

到此這篇關(guān)于Python的PIL庫中g(shù)etpixel方法的使用的文章就介紹到這了,更多相關(guān)Python getpixel內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 十堰市| 临沂市| 灵璧县| 望奎县| 富源县| 兴义市| 汝州市| 紫云| 大兴区| 忻城县| 莫力| 宁化县| 苗栗县| 花垣县| 龙江县| 杭州市| 如东县| 博爱县| 黄石市| 金溪县| 文昌市| 淮北市| 宁远县| 峡江县| 九江市| 延寿县| 桃源县| 怀宁县| 彭州市| 广南县| 永昌县| 逊克县| 黎城县| 城步| 福清市| 宜城市| 永定县| 眉山市| 黑龙江省| 灌阳县| 定安县|