软件OpenEXR用python实现的exr文件通道检测与数据统计
HolioFox感觉 exr 文件不能很直观地看到各个通道的数据,多有不便,于是借助 python 可以对 exr 文件进行通道检测与数据直方图统计
通道检测
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| import OpenEXR import Imath import numpy as np
file_path = 'D:\work path'
exr_file = OpenEXR.InputFile(file_path)
header = exr_file.header() channel_info = header['channels']
print("可用通道:", list(channel_info.keys()))
|
数据统计
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
| import OpenEXR import Imath import numpy as np import matplotlib.pyplot as plt
file_path = 'D:\work path'
exr_file = OpenEXR.InputFile(file_path)
header = exr_file.header() channel_info = header['channels']
for channel_name in channel_info: channel_data = exr_file.channel(channel_name) channel_array = np.frombuffer(channel_data, dtype=np.float32) channel_min = np.min(channel_array) channel_max = np.max(channel_array) print(f"通道 {channel_name}: 最小值={channel_min}, 最大值={channel_max}")
plt.hist(channel_array, bins=100) plt.title(f"Channel {channel_name} Distribution") plt.show()
|