用python实现的exr文件通道检测与数据统计

感觉 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文件
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文件
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()