读取、处理和显示.EXR格式图像中的像素

4

我想读取exr文件格式的图像,并查看相应位置的像素强度。同时也想将它们叠加在一起,用于神经网络。如何对这些格式进行正常的图像处理?请帮助我完成这个任务!

我尝试了使用OpenEXR文件的代码,但无法进一步操作。

import OpenEXR
file = OpenEXR.InputFile('file_name.exr')

我希望看到像常规图像处理工具一样的IT技术工具,例如

file.size()
file.show()
file.write('another format')
file.min()
file.extract_channels()
file.append('another exr file')

请查看此问题的答案。 - Nagabhushan S N
2个回答

4

OpenEXR似乎缺乏像显示图像或将图像保存为不同格式等高级图像处理功能。对于此,我建议您使用 OpenCV,它充满了图像处理功能。

您需要做的是:

  • 仅使用 OpenEXR 读取 exr ,然后提取通道并将它们转换为numpy数组,如 rCh = np.asarray(rCh,dtype = np.uint8)
  • 从这些numpy数组创建RGB图像,如 img_rgb = cv2.merge([b,g,r])
  • 使用OpenCV函数进行您列出的操作:
    • 尺寸: img_rgb.shape
    • 展示: cv2.imshow(img_rgb)
    • 写入: cv2.imwrite("path/to/file.jpg", img_rgb)
    • 最小值: np.min(b), np.min(g), np.min(r)
    • 提取通道: b, g, r = cv2.split(img_rgb)

1
这似乎是一个相当明智的方法。 - Mark Setchell

2

在OpenEXR网页上有一个示例

import sys
import array
import OpenEXR
import Imath

if len(sys.argv) != 3:
    print "usage: exrnormalize.py exr-input-file exr-output-file"
    sys.exit(1)

# Open the input file
file = OpenEXR.InputFile(sys.argv[1])

# Compute the size
dw = file.header()['dataWindow']
sz = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)

# Read the three color channels as 32-bit floats
FLOAT = Imath.PixelType(Imath.PixelType.FLOAT)
(R,G,B) = [array.array('f', file.channel(Chan, FLOAT)).tolist() for Chan in ("R", "G", "B") ]

接下来,您应该拥有三个浮点数据数组,每个通道一个。您可以轻松将它们转换为numpy数组,并按照用户@ZdaR的建议继续使用opencv


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接