本文整理匯總了Python中rawpy.imread方法的典型用法代碼示例。如果您正苦於以下問題:Python rawpy.imread方法的具體用法?Python rawpy.imread怎麽用?Python rawpy.imread使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rawpy
的用法示例。
在下文中一共展示了rawpy.imread方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_dng
# 需要導入模塊: import rawpy [as 別名]
# 或者: from rawpy import imread [as 別名]
def load_dng(filename, **kwargs):
"""Loads a dng image file from disk into a float32 Numpy Array (OpenCV view).
Requires rawpy.
Args:
filename (str): Name of pfm image file.
**kwargs: Extra keyword arguments to pass to `rawpy.postprocess()`.
"""
import rawpy
filename = process(filename)
with rawpy.imread(filename) as raw:
default_kwargs = dict(gamma=(1,1), no_auto_bright=True, output_bps=16)
default_kwargs.update(kwargs)
img = raw.postprocess(**default_kwargs)
return rgb2bgr(img,-1).astype('float32')
# Accepts hwc - BGR float32 numpy array (cv style)
# TODO: Improve multiple views support
# TODO: Improve speed
示例2: imread
# 需要導入模塊: import rawpy [as 別名]
# 或者: from rawpy import imread [as 別名]
def imread(filename):
"""Reads an image file from disk into a Numpy Array (OpenCV view).
Args:
filename (str): Name of pfm image file.
"""
filename = process(filename)
ext = os.path.splitext(filename)[1]
if ext.lower() == '.pfm':
return load_pfm(filename)
elif ext.lower() == '.dng':
return load_dng(filename)
else:
loaded = cv2.imread(filename, flags=cv2.IMREAD_ANYDEPTH + cv2.IMREAD_COLOR)
if loaded is None:
raise IOError('Could not read {0}'.format(filename))
else:
return loaded
示例3: load_image
# 需要導入模塊: import rawpy [as 別名]
# 或者: from rawpy import imread [as 別名]
def load_image(path):
if(path[-3:] == 'dng'):
import rawpy
with rawpy.imread(path) as raw:
img = raw.postprocess()
elif(path[-3:]=='bmp' or path[-3:]=='jpg' or path[-3:]=='png'):
import cv2
return cv2.imread(path)[:,:,::-1]
else:
img = (255*plt.imread(path)[:,:,:3]).astype('uint8')
return img
示例4: get_visible_raw_image
# 需要導入模塊: import rawpy [as 別名]
# 或者: from rawpy import imread [as 別名]
def get_visible_raw_image(image_path):
raw_image = rawpy.imread(image_path).raw_image_visible.copy()
# raw_image = rawpy.imread(image_path).raw_image.copy()
return raw_image
示例5: load_image
# 需要導入模塊: import rawpy [as 別名]
# 或者: from rawpy import imread [as 別名]
def load_image(path):
if(path[-3:] == 'dng'):
import rawpy
with rawpy.imread(path) as raw:
img = raw.postprocess()
# img = plt.imread(path)
elif(path[-3:]=='bmp' or path[-3:]=='jpg' or path[-3:]=='png'):
import cv2
return cv2.imread(path)[:,:,::-1]
else:
img = (255*plt.imread(path)[:,:,:3]).astype('uint8')
return img
示例6: load_image
# 需要導入模塊: import rawpy [as 別名]
# 或者: from rawpy import imread [as 別名]
def load_image(path):
if (path[-3:] == 'dng'):
import rawpy
with rawpy.imread(path) as raw:
img = raw.postprocess()
# img = plt.imread(path)
elif (path[-3:] == 'bmp' or path[-3:] == 'jpg' or path[-3:] == 'png'):
import cv2
return cv2.imread(path)[:, :, ::-1]
else:
img = (255 * plt.imread(path)[:, :, :3]).astype('uint8')
return img
示例7: apply
# 需要導入模塊: import rawpy [as 別名]
# 或者: from rawpy import imread [as 別名]
def apply(model_path, filenames_short, exposure_time_sec):
import rawpy
import cv2
import numpy as np
from prepare_sony import pack_raw
import glob
import tqdm
if os.path.isfile(filenames_short):
filenames_short = [filenames_short]
else:
filenames_short = glob.glob(filenames_short)
# assume all images have same shape to avoid multiple loads of the checkpoint
short_raw = rawpy.imread(filenames_short[0])
short_uint16 = pack_raw(short_raw)
short_float = short_uint16.astype(np.float32)
short_float = np.maximum(short_float - 512, 0) / (16383 - 512)
H, W, _ = short_float.shape
predict_func = OfflinePredictor(PredictConfig(
model=Model(H, W),
session_init=get_model_loader(model_path),
input_names=['short_exposure'],
output_names=['prediction']))
# apply model to all images
for filename_short in tqdm.tqdm(filenames_short):
in_exposure_time = float(filename_short.split('_')[-1].replace('s.ARW', ''))
factor = exposure_time_sec / in_exposure_time
short_raw = rawpy.imread(filename_short)
short_uint16 = pack_raw(short_raw)
short_float = short_uint16.astype(np.float32)
short_float = np.maximum(short_float - 512, 0) / (16383 - 512)
short_float *= factor
pred = predict_func(short_float[None, ...])[0][0, ...]
p = np.clip(pred * 255, 0, 255)
out_fn = 'outputs/{}-{}-prediction.jpg'.format(os.path.basename(filename_short)[:-4], exposure_time_sec)
cv2.imwrite(out_fn, p[:, :, ::-1])
naive_uint16 = short_raw.postprocess(use_camera_wb=True, half_size=False, no_auto_bright=True, output_bps=16)
naive_float = naive_uint16.astype(np.float32) / 65535.0
# naive_float *= factor
naive_float *= pred.mean() / naive_float.mean()
p = np.clip(naive_float * 255, 0, 255)
out_fn = 'outputs/{}-{}-noise.jpg'.format(os.path.basename(filename_short)[:-4], exposure_time_sec)
cv2.imwrite(out_fn, p[:, :, ::-1])