def pointlight2envmap(imseq, indexfn, envmap, scale, output, w, h): #load images #interpolate envmap = cvgim.imread(envmap) envmap = cvgim.resize(envmap, dx=w, dy=h) h = envmap.shape[0] w = envmap.shape[1] envmap = envmap[:, :, :3] print(envmap.shape) index = util.loadPickle(indexfn) assert len(index) == h * w x = np.linspace(0, w - 1, w) y = np.linspace(0, h - 1, h) u = (x + 0.5) / w v = (y + 0.5) / h u, v = np.meshgrid(u, v) x, y = np.meshgrid(x, y) sintScaled = np.sin(v * np.pi) * scale sumsin = sintScaled.sum() img = cvgim.imread(imseq % int(index['0000_0000']))[:, :, :3] * 0 for x0, y0, intensity, idx in tqdm.tqdm( zip( x.reshape(-1).astype(np.int32), y.reshape(-1).astype(np.int32), envmap.reshape(-1, 3), index.values())): intensity = envmap[y0, x0, None, None, :] * sintScaled[y0, x0] fn = os.path.join(imseq % int(index['%04d_%04d' % (x0, y0)])) im = cvgim.imread(fn)[:, :, :3] img += im * intensity / w * h cvgim.imwrite(output, img.astype(np.float32)[:, :, ::-1]) cvgim.imwrite(output.replace('exr', 'png'), (np.clip(img[:, :, ::-1], 0, 1)**(1 / 2.2) * (2**16 - 1)).astype(np.uint16)) return img.astype(np.float32)[:, :, ::-1].copy()
import numpy as np import glob import cvgutils.Image as cvgim import os import tqdm indir = '/home/mohammad/Projects/NRV/dataset/envmaps/*.exr' outdir = '/home/mohammad/Projects/NRV/dataset/envmaps_512_1024' inimgs = glob.glob(indir) max16 = (2**16 - 1) for img in tqdm.tqdm(inimgs): im = cvgim.imread(img) im = cvgim.resize(im, dx=1024, dy=512) fn = os.path.join(outdir, os.path.basename(img).replace('4k', '1024x512')) # im = (im * max16).astype(np.uint16) cvgim.imwrite(fn, im)
import cvgutils.Image as img import numpy as np import cv2 im = (cv2.imread('tests/testimages/highfreq.jpg', -1) / 255.0)**(2.2) res = img.resize(im, dx=256, dy=256) cv2.imshow('hi', (res**(1 / 2.2) * 255).astype(np.uint8)) cv2.waitKey(0)