python读取raw binary图片并提取统计信息的实例

时间:2021-05-22

用python语言读取二进制图片文件,并提取非零数据统计信息(例如:max,min,skewness and kurtosis)

python新手,注释较少,欢迎指教

import structimport mathimport numpyimport scipy.stats filename = input('enter file name')f = open(filename, 'rb')f.seek(0, 0) c = 0numOfZero = 0s = 0num = []m = 0 while True: temp = f.read(4) if len(temp) == 0: break else: c = c + 1print(c)print(numOfZero) sum = 0squSum = 0min = 2000max = 0list = []num = []f.seek(0, 0) for i in range(0, c): a = f.read(4) b = struct.unpack('<f', a) list.append(b[0]) if list[i] == 0: numOfZero = numOfZero + 1 else: num.append(b[0]) if list[i] > max: max = list[i] if list[i] < min and list[i] != 0: min = list[i] sum = sum + list[i] stan_Dev = numpy.std(num)median = numpy.median(num)sk = scipy.stats.skew(num)ku = scipy.stats.kurtosis(num) print('numOfZero = ', numOfZero)print('sum = ', sum)print('meanValue = ',sum / (c - numOfZero))print('maxValue = ', max)print('minValue = ', min)print('median = ', median)print('stdev = ', stan_Dev)print('skewness = ', sk)print('kurtosis = ', ku) f.close()

以上这篇python读取raw binary图片并提取统计信息的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章