您好,登錄后才能下訂單哦!
用python語言讀取二進制圖片文件,并提取非零數據統計信息(例如:max,min,skewness and kurtosis)
python新手,注釋較少,歡迎指教
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圖片并提取統計信息的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。