forked from cchen156/Learning-to-See-in-the-Dark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_RAW.py
37 lines (28 loc) · 1.18 KB
/
convert_RAW.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import numpy as np
import rawpy
import glob
from matplotlib import pyplot as plt
import multiprocessing
input_dir = './dataset/Sony/short/'
output_dir = './dataset/Sony/short/JPEG'
if not os.path.exists(output_dir):
os.makedirs(output_dir)
im_sets = glob.glob(input_dir + '*.ARW')
# for raw_file in im_sets:
# print(os.path.basename(raw_file))
# raw_map = rawpy.imread(raw_file)
# im = raw_map.postprocess(use_camera_wb=True, half_size=False, no_auto_bright=True, output_bps=16)
# im = np.expand_dims(np.float32(im / 65535.0), axis=0)
# plt.imsave(os.path.join(output_dir, os.path.splitext(os.path.basename(raw_file))[0]+'.png'), im.squeeze(0))
def convert_raw(raw_file):
print(os.path.basename(raw_file))
raw_map = rawpy.imread(raw_file)
im = raw_map.postprocess(use_camera_wb=True, half_size=False, no_auto_bright=True, output_bps=16)
im = np.expand_dims(np.float32(im / 65535.0), axis=0)
plt.imsave(os.path.join(output_dir, os.path.splitext(os.path.basename(raw_file))[0] + '.png'), im.squeeze(0))
if __name__ == '__main__':
pool = multiprocessing.Pool(processes=16)
pool.map(convert_raw, im_sets)
pool.close()
pool.join()