Through this example, some Canon EOS 5D Mark II CR2 files will be merged together in order to create a single radiance image.
The following steps will be taken:
In [1]:
import logging
import os
import rawpy
import colour
from colour.plotting import *
from colour_hdri import (
EXAMPLES_RESOURCES_DIRECTORY,
Image,
ImageStack,
filter_files,
image_stack_to_radiance_image,
weighting_function_Debevec1997)
from colour_hdri.plotting import plot_radiance_image_strip
logging.basicConfig(level=logging.INFO)
RESOURCES_DIRECTORY = os.path.join(EXAMPLES_RESOURCES_DIRECTORY,
'frobisher_001')
colour.utilities.filter_warnings()
colour.utilities.describe_environment();
In [2]:
colour_style();
In [3]:
RAW_FILES = filter_files(RESOURCES_DIRECTORY, ('CR2',))
In [4]:
def read_raw_file(path):
raw = rawpy.imread(path).postprocess(gamma=(1, 1),
no_auto_bright=True,
output_bps=16)
return raw.astype(float) / 65535.
plot_image(colour.cctf_encoding(
read_raw_file(RAW_FILES[-2])[1250:2250, 3000:4000, ...]),
{'text': os.path.basename(RAW_FILES[-2])});
In [5]:
def merge_from_raw_files_using_rawpy(
raw_files,
output_directory,
batch_size=5,
weighting_function=weighting_function_Debevec1997):
paths = []
for raw_files in colour.utilities.batch(raw_files, batch_size):
image_stack = ImageStack()
for raw_file in raw_files:
image = Image(raw_file)
image.read_metadata()
image.data = read_raw_file(raw_file)
image_stack.append(image)
path = os.path.join(
output_directory,
'{0}_{1}_MRFUR.{2}'.format(
os.path.splitext(os.path.basename(image_stack.path[0]))[0],
batch_size,
'exr'))
paths.append(path)
logging.info('Merging "{0}"...'.format(path))
logging.info('\tImage stack "F Number" (Exif): {0}'.format(
image_stack.f_number))
logging.info('\tImage stack "Exposure Time" (Exif): {0}'.format(
image_stack.exposure_time))
logging.info('\tImage stack "ISO" (Exif): {0}'.format(
image_stack.iso))
image = image_stack_to_radiance_image(image_stack,
weighting_function,
weighting_average=True)
logging.info('Writing "{0}"...'.format(path))
colour.write_image(image, path)
return paths
PATHS = merge_from_raw_files_using_rawpy(
RAW_FILES, RESOURCES_DIRECTORY)
In [6]:
plot_radiance_image_strip(colour.read_image(PATHS[0]));