我想知道.bmp图像的位深度。这在windows中很容易手动完成(Properties>;Details..),但谷歌在这方面似乎做得不多,我在这里看到的一个答案(对我来说)也没有说明如何做到这一点
How to find the Bit Depth of an image
代码
import png as png
import numpy as np
r=png.Reader(filename = r'C:\Users\priper\Desktop\OPW_refac\grayscale.png')
a = r.read()
print(a[3]['bitdepth'])
或
from PIL import Image
import numpy as np
#Load the BMP file
img = Image.open(r'C:\Users\priper\Desktop\OPW_refac\HSS All As.bmp')
print(img, '\n')
print('bit depth :', img.mode)#this only tells me it is 8 pixels, I don't think it could tell me if it was 4.
#Or as a numpy array
img = np.array(Image.open(r'C:\Users\priper\Desktop\OPW_refac\HSS All As.bmp'))
print(img)
我可以读取png的位深度,但不知道哪个库可以如此容易地从bmp中获取类似的信息
使用合适的库(如
wand
或exiftool
)可能会更好,但如果您想要一些轻量级的东西,这可能就足够了-但我无法在您的图像上测试它,因为您没有共享任何:我用ImageMagick创建了一个示例BMP,如下所示:
然后,我运行脚本并获得了
bpp:16
匹配的exiftool
输出:然后我创建了一个24位BMP,如下所示:
我的Python和
exiftool
都报告了24个bpp关键字:Python。BMP,图像处理,获取深度,位深度,bpp
相关问题 更多 >
编程相关推荐