makehdr

Create high dynamic range image

Syntax

HDR = makehdr(files)
HDR = makehdr(imds)
HDR = makehdr(___,Name,Value)

Description

example

HDR = makehdr(files) creates the single-precision, high dynamic range (HDR) image HDR from the set of spatially registered, low dynamic range (LDR) images in files.

HDR = makehdr(imds) creates the single-precision, high dynamic range image HDR from the set of spatially registered LDR images stored as ImageDatastore object, imds.

example

HDR = makehdr(___,Name,Value) uses name-value pairs to control various aspects of the image creation in addition to the input argument from any of the previous syntaxes.

Note

The input image files must contain the Exchangeable Image File Format (EXIF) exposure metadata. makehdr uses the middle exposure between the brightest and darkest images as the base exposure for the HDR calculations. This value does not need to appear in any particular file. For more information about calculating this middle exposure value, see Algorithms.

Examples

collapse all

Create a high dynamic range (HDR) image from a set of low dynamic range (LDR) images that share the same f-stop but have different exposure times.

Load six low dynamic range images into the workspace. Create a vector of their respective exposure times. Display the images as a montage.

files = {'office_1.jpg','office_2.jpg','office_3.jpg',...
         'office_4.jpg','office_5.jpg','office_6.jpg'};
expTimes = [0.0333 0.1000 0.3333 0.6250 1.3000 4.0000];
montage(files)

Combine the LDR images into an HDR image.

hdr = makehdr(files,'RelativeExposure',expTimes./expTimes(1));

Display the HDR image.

rgb = tonemap(hdr);
imshow(rgb)

Create a high dynamic range (HDR) image from a set of six low dynamic range (LDR) images that share the same f-stop but have different exposure times. The estimated camera response function values are computed from these LDR images and used to generate an HDR image.

Read the set of six spatially registered, LDR images into the workspace. Create an imageDatastore object containing these images. Display the images as a montage.

setDir = fullfile(toolboxdir('images'),'imdata','office_*');
imds = imageDatastore(setDir);
montage(imds)

Estimate the camera response function from images in the datastore.

crf = camresponse(imds);

Combine the LDR images into an HDR image by using the estimated camera response function values.

hdr = makehdr(imds,'CameraResponse',crf);

Display the HDR image.

rgb = tonemap(hdr);
imshow(rgb)

Input Arguments

collapse all

Set of spatially registered LDR images, specified as a string array or a cell array of character vectors. These images can be color or grayscale of any bit depth. However, the preferred bit depth for LDR images is 8 or 16.

Data Types: char | string | cell

Set of spatially registered LDR images, specified as an ImageDatastore object. These images can be color or grayscale of any bit depth. However, the preferred bit depth for LDR images is 8 or 16.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: makehdr(files,'RelativeExposure',[0.1 0.3 0.4]);

Name of file to use as base exposure, specified as a string scalar or character vector.

Data Types: char | string

Note

You can use only one of the 'BaseFile', 'ExposureValues', and 'RelativeExposure' name-value pairs at a time.

Exposure value of each file in input set, specified as a numeric vector of positive values. The kth element in the vector corresponds to the kth LDR image in the input set. An increase of one exposure value (EV) corresponds to doubling the exposure. A decrease of one EV corresponds to halving the exposure. If you specify this parameter, the function overrides the EXIF exposure metadata.

Data Types: single | double

Relative exposure value of each file in input set, specified as a numeric vector of positive values. The kth element in the vector corresponds to the kth LDR image in the input set.

For example, an image with a relative exposure (RE) value of 0.5 has half as much exposure as an image with an RE value of 1. Similarly, an image with an RE value of 3 has three times the exposure of an image with an RE value of 1. If you specify this parameter, the function overrides the EXIF exposure metadata.

Data Types: single | double

Minimum correctly exposed value, specified as a positive integer. For each LDR image, pixels with a smaller value than this minimum are considered underexposed and do not contribute to the final HDR image. By default, this minimum value is set to 2% of the maximum intensity allowed by the image data type.

Data Types: single | double

Maximum correctly exposed value, specified as a positive integer. For each LDR image, pixels with a larger value than this maximum are considered overexposed and do not contribute to the final HDR image. By default, this maximum value is set to 98% of the maximum intensity allowed by the image data type.

Data Types: single | double

Camera response function, specified as a n-by-1 vector for grayscale images and n-by-3 matrix for color images. The camera response function maps the log-exposure value (scene radiance) to the intensity levels in the input images. The value of n is 2bit depth. For example, if the bit depth of the input set of images is 8, then n is 256.

Note

The 'MaximumLimit' and 'MinimumLimit' name-value pairs are ignored when 'CameraResponse' is specified.

Data Types: single | double

Output Arguments

collapse all

High dynamic range image, returned as an m-by-n-by-3 numeric array.

Data Types: single

Algorithms

The makehdr function calculates the middle exposure value by using the exposure values (EVs) of the input images. The exposure value for each image is computed based on the aperture and shutter speed. The aperture and shutter speed values are stored in the EXIF metadata of that input file or is specified using the 'ExposureValues' name-value pair. The middle EV is calculated as an average of the highest and lowest EVs and is used as the base exposure.

References

[1] Reinhard et al. High Dynamic Range Imaging 2006. Ch. 4.

[2] Debevec, P.E., and J. Malik. "Recovering High Dynamic Range Radiance Maps from Photographs." In ACM SIGGRAPH 2008 classes, Article No. 31. New York, NY: ACM, 2008.

Introduced in R2008a