光场相机拍摄的原图(raw文件)的像素之间是按照一定规则排列的,设光场的角分辨率为$U\times V$,子光圈图像分辨率为$X\times Y$,那么这$U\times V$副图像合成后的原图分辨率应该是$(U*X)\times (V*Y)$,但是不同的相机像素排列方式是不同的,这里总结的方法只适用于需要还原回去的原图排列方式为横纵排列,而不是六边形排列之类的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import os import numpy as np from PIL import Image from matplotlib import pyplot as plt
xy_size = 1080 UV_solution = 7 img_dir = '' full_img = np.zeros([xy_size * UV_solution, xy_size * UV_solution, 3]) for img_x in range(UV_solution): for img_y in range(UV_solution): img_order = img_x * UV_solution + img_y img_name = '...' img_path = os.path.join(img_dir, img_name) img_np = np.asarray(Image.open(img_path)) full_img[img_x::UV_solution, img_y::UV_solution] = img_np
LF_img = Image.fromarray(full_img.astype('uint8')).convert('RGB') LF_img.show() LF_img_name = img_dir.split('/')[-1] + '.png' LF_img_save_path = os.path.dirname(img_dir) LF_img.save(LF_img_save_path + '/' + LF_img_name)
|