读取 .png 的有效位数?
Read number of significant bits of .png?
我有一组 16 位 png 文件,用 LabVIEW 记录。出于某种原因,我需要对它们进行位移才能使用它们。为此,我需要有效位数。我怎样才能阅读那些使用 Python 的内容?在 Matlab 中,有一种名为 imfinfo 的方法,其中 returns 有效位。
根据@Glen Randers-Pehrson 的建议,我刚刚阅读了 sBIT 块:
import struct
import binascii
def __header(bytes):
return struct.unpack('>NNccccc', bytes)
def __getSBit(bytes):
bytes = bytes[8:]
sBit = 0
while bytes:
length = struct.unpack('>I', bytes[:4])[0]
bytes = bytes[4:]
chunk_type = bytes[:4]
bytes = bytes[4:]
chunk_data = bytes[:length]
bytes = bytes[length:]
if chunk_type == "sBIT":
sBit = int(chunk_data.encode("hex"), 16)
break
bytes = bytes[4:]
return sBit
def getSigniticantBits(filename):
with open(filename, 'rb') as f:
bytes = f.read()
return __getSBit(bytes)
我有一组 16 位 png 文件,用 LabVIEW 记录。出于某种原因,我需要对它们进行位移才能使用它们。为此,我需要有效位数。我怎样才能阅读那些使用 Python 的内容?在 Matlab 中,有一种名为 imfinfo 的方法,其中 returns 有效位。
根据@Glen Randers-Pehrson 的建议,我刚刚阅读了 sBIT 块:
import struct
import binascii
def __header(bytes):
return struct.unpack('>NNccccc', bytes)
def __getSBit(bytes):
bytes = bytes[8:]
sBit = 0
while bytes:
length = struct.unpack('>I', bytes[:4])[0]
bytes = bytes[4:]
chunk_type = bytes[:4]
bytes = bytes[4:]
chunk_data = bytes[:length]
bytes = bytes[length:]
if chunk_type == "sBIT":
sBit = int(chunk_data.encode("hex"), 16)
break
bytes = bytes[4:]
return sBit
def getSigniticantBits(filename):
with open(filename, 'rb') as f:
bytes = f.read()
return __getSBit(bytes)