2024-06-11 14:07:50 发布
网友
我有一套16位pngs文件,用LabVIEW录制。出于某种原因,我需要改变它们来使用它们。对于这个,我需要有效位的数量。如何使用Python阅读这些内容?在Matlab中,有一种方法叫做imfinfo,它返回有效位。你知道吗
正如@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)
正如@Glen Randers Pehrson所建议的,我只是阅读了sBIT块:
相关问题 更多 >
编程相关推荐