python如何讀取像素值的方法:
使用image模塊中的getpixel函數獲得像素值。
GetPixel函數檢索指定坐標點的像素的RGB顏色值。
函數原型:
COLORREFGetPixel(HDChdc,intnXPos,intnYPos)
參數:
hdc:設備環境句柄。
nXPos:指定要檢查的像素點的邏輯X軸坐標。
nYPos:指定要檢查的像素點的邏輯Y軸坐標。
示例:
importImage
importsys
im=Image.open(sys.argv[1])
width=im.size[0]
height=im.size[1]
print"/*width:%d*/"%(width)
print"/*height:%d*/"%(height)
count=0
forhinrange(0,height):
forwinrange(0,width):
pixel=im.getpixel((w,h))
foriinrange(0,3):
count=(count+1)%16
if(count==0):
print"0x%02x,/n"%(pixel[i]),
else:
print"0x%02x,"%(pixel[i]),
以上內容為大家介紹了python如何讀取像素值,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構:千鋒教育。