def imread(filename, format_="float32"): """Reads an image. Supports exr, hdr, cr2, tiff, jpg, png and everything SciPy/PIL supports. :filename: file path. :format_: format in which to return the value. If set to "native", the native format of the file will be given (e.g. uint8 for jpg). """ ldr = False _, ext = os.path.splitext(filename.lower()) if ext == '.exr': im = ezexr.imread(filename) elif ext in ['.hdr', '.pic']: im = _hdr_read(filename) elif ext in ['.cr2', '.nef', '.raw']: im = _raw_read(filename) elif ext in ['.tiff', '.tif']: try: import tifffile as tiff except ImportError: #print('Install tifffile for better tiff support. Fallbacking to scipy.') im = scipy_io.imread(filename) else: im = tiff.imread(filename) else: im = scipy_io.imread(filename) ldr = True if format_ == "native": return im elif ldr and not 'int' in format_: return im.astype(format_) / 255. else: return im.astype(format_)
ts = time.time() with open("output.npz", "rb") as fhdl: data = np.load(fhdl) T = data["arr_0"] normals = data["arr_1"] img_size = data["arr_2"] print("time: {:.03f}".format(time.time() - ts)) # Save the normals imsave('normals.png', (normals + 1) / 2) #from matplotlib import pyplot as plt #plt.imshow((normals + 1)/2); plt.show() # Load the envmap ts = time.time() envmap = imread("envmap.exr", rgb=True) envmap = zoom(envmap, (128 / envmap.shape[0], 256 / envmap.shape[1], 1), order=1, prefilter=True) envmap = envmap[:64, :, :] print("time: {:.03f}".format(time.time() - ts)) for i in range(256): envmap = np.roll(envmap, shift=1, axis=1) # Perform the rendering ts = time.time() im = T.dot(envmap.reshape((-1, 3))) # Tonemap & reshape im = im.reshape((img_size[0], img_size[1], 3))**(1. / 2.2) print("Render performed in {:.3f}s".format(time.time() - ts))