简体   繁体   English

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

[英]Read, process and show the pixels in .EXR format images

I want to read the exr file format images and see the pixel intensities in the corresponding location.我想读取 exr 文件格式的图像并查看相应位置的像素强度。 And also wanted to stack them together to give them into a neural network.并且还想将它们堆叠在一起以将它们组成一个神经网络。 How can I do the normal image processing on these kind of formats?如何对这些格式进行正常的图像处理? Please help me in doing this!请帮我做这件事!

I have tried this code using OpenEXR file but unable to proceed further.我已经使用 OpenEXR 文件尝试了此代码,但无法继续进行。

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

I am expected to see the normal image processing tools like我预计会看到正常的图像处理工具,例如

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

OpenEXR seems to be lacking the fancy image processing features such as displaying images or saving the image to a different format. OpenEXR 似乎缺乏花哨的图像处理功能,例如显示图像或将图像保存为不同的格式。 For this I would suggest you using OpenCV , which is full of image processing features.为此,我建议您使用OpenCV ,它具有丰富的图像处理功能。

What you may need to do is:您可能需要做的是:

  • Read exr using OpenEXR only, then extract channels and convert them to numpy arrays as rCh = np.asarray(rCh, dtype=np.uint8)仅使用OpenEXR读取exr ,然后提取通道并将它们转换为 numpy 数组,如rCh = np.asarray(rCh, dtype=np.uint8)
  • Create a RGB image from these numpy arrays as img_rgb = cv2.merge([b, g, r]) .从这些 numpy 数组创建一个 RGB 图像,如img_rgb = cv2.merge([b, g, r])
  • Use OpenCV functions for your listed operations:将 OpenCV 函数用于您列出的操作:
    • Size: img_rgb.shape尺寸: img_rgb.shape
    • Show: cv2.imshow(img_rgb)显示: cv2.imshow(img_rgb)
    • Write: cv2.imwrite("path/to/file.jpg", img_rgb)写入: cv2.imwrite("path/to/file.jpg", img_rgb)
    • Min: np.min(b) , np.min(g) , np.min(r)最小值: np.min(b)np.min(g)np.min(r)
    • Extract channels: b, g, r = cv2.split(img_rgb)提取通道: b, g, r = cv2.split(img_rgb)

There is an example on the OpenEXR webpage: 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") ]

After this, you should have three arrays of floating point data, one per channel.在此之后,您应该拥有三个浮点数据数组,每个通道一个。 You could easily convert these to numpy arrays and proceed with opencv as user @ZdaR suggests.您可以轻松地将这些转换为numpy数组,并按照用户@ZdaR 的建议继续使用opencv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM