0
我正在編寫腳本來檢查圖像是否正常化。我正在使用Python PNG模塊來分析圖像。爲了測試它,我在Photoshop中創建了一個由2像素線和黑白像素組成的16位圖像。 我的腳本正確地標識了黑色像素(0),但是它給出了一個與我期望的(65535)不同的值(65533),用於白色像素。16位灰度png圖像的Python圖像處理
我不明白爲什麼會發生這種情況。我的腳本有問題嗎?它與Photoshop保存圖像的方式有關嗎?
簡約測試png圖片:http://i.imgur.com/70D0F.png
腳本:
#!/usr/bin/python
import sys
import png # https://pypi.python.org/pypi/pypng
if len(sys.argv) != 2:
print "Invalid number of arguments (",len(sys.argv),").\nUsage: python getMinMaxColor.py png_file"
sys.exit(-1)
pngFilePath = sys.argv[1]
f = open(pngFilePath, 'rb')
r = png.Reader(file=f)
k = r.read()
bitDepth = 16
if k[3]['bitdepth'] != None:
bitDepth = k[3]['bitdepth']
absMaxColor = 2**bitDepth-1
maxColor = -1
minColor = absMaxColor+1
print "Content:"
for line in k[2]:
for color in line:
print color
if (color > maxColor):
maxColor = color
if (color < minColor):
minColor = color
f.close()
print "\n"
print "Min Color:", minColor
print "Max Color:", maxColor, "(max:", absMaxColor, ")"
if minColor == 0 and maxColor == absMaxColor:
print "Image is normalized"
else:
print "Image is not normalized"