Reputation: 231
I want to read the exr file format images and see the pixel intensities in the corresponding location. 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.
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')
Upvotes: 4
Views: 5497
Reputation: 1296
There is an example on the OpenEXR webpage:
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.
Upvotes: 2
Reputation: 22964
OpenEXR seems to be lacking the fancy image processing features such as displaying images or saving the image to a different format. For this I would suggest you using OpenCV
, which is full of image processing features.
What you may need to do is:
exr
using OpenEXR
only, then extract channels and convert them to numpy arrays as rCh = np.asarray(rCh, dtype=np.uint8)
img_rgb = cv2.merge([b, g, r])
.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)
Upvotes: 4