Through this example, some Canon EOS 5D Mark II CR2 files converted to low dynamic range sRGB colourspace Tiff files will be merged together in order to create a single radiance image.
The following steps will be taken:
In [1]:
import glob
import logging
import matplotlib.pyplot as plt
import numpy as np
import os
import shlex
import subprocess
import colour
from colour.plotting import *
from colour_hdri import (
EXAMPLES_RESOURCES_DIRECTORY,
ImageStack,
camera_response_functions_Debevec1997,
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',))
for path in RAW_FILES:
logging.info('Converting "{0}" to "Tiff" file...'.format(path))
subprocess.call(['dcraw'] + shlex.split('-w -W -H 0 -q 3 -T "{0}"'.format(path)))
TIFF_FILES = sorted(glob.glob('{0}/*.tiff'.format(RESOURCES_DIRECTORY)))
In [4]:
CRFS = camera_response_functions_Debevec1997(
ImageStack.from_files(TIFF_FILES[2:5]))
CRFS = CRFS[np.all(CRFS, axis=1)]
CRFS = colour.utilities.linear_conversion(CRFS, (np.min(CRFS), 1), (0, 1))
plt.plot(CRFS)
plt.show();
In [5]:
def merge_from_ldr_files(
ldr_files,
output_directory,
camera_response_functions,
batch_size=5):
paths = []
for ldr_files in colour.utilities.batch(ldr_files, batch_size):
image_stack = ImageStack.from_files(ldr_files)
path = os.path.join(
output_directory,
'{0}_{1}_MLF.{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, camera_response_functions=camera_response_functions)
image[np.isnan(image)] = 0
logging.info('Writing "{0}"...'.format(path))
colour.write_image(image, path)
return paths
PATHS = merge_from_ldr_files(
TIFF_FILES, RESOURCES_DIRECTORY, CRFS)
In [6]:
plot_radiance_image_strip(colour.read_image(PATHS[0]));