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

时间:2021-10-12 07:51:40

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import struct
import math
import numpy
import scipy.stats
 
filename = input('enter file name')
f = open(filename, 'rb')
f.seek(0, 0)
 
c = 0
numOfZero = 0
s = 0
num = []
m = 0
 
while True:
  temp = f.read(4)
  if len(temp) == 0:
    break
  else:
    c = c + 1
print(c)
print(numOfZero)
 
sum = 0
squSum = 0
min = 2000
max = 0
list = []
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图片并提取统计信息的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/oldveteran/article/details/52041119