Main Content

makehdr

Create high dynamic range image

Description

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.

example

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.

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.

example

HDR = makehdr(images,Name,Value) creates the single-precision HDR image HDR from the set of spatially registered LDR images stored in a cell array images. Specify the exposure values for images in the input cell array by using the name-value pair 'ExposureValues' or 'RelativeExposure'.

Note

When input is a cell array of LDR images, you must specify either the exposure or the relative exposure values as the second input argument. To specify the exposure values, use the name-value pair 'ExposureValues'. To specify the relative exposure values, use the name-value pair 'RelativeExposure'.

example

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)

Figure contains an axes object. The hidden axes object contains an object of type image.

Combine the LDR images into an HDR image.

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

Display the HDR image.

rgb = tonemap(hdr);
imshow(rgb)

Figure contains an axes object. The hidden axes object contains an object of type image.

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)

Figure contains an axes object. The hidden axes object contains an object of type image.

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)

Figure contains an axes object. The hidden axes object contains an object of type image.

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

Read six low dynamic range images into the workspace.

image1 = imread('office_1.jpg');
image2 = imread('office_2.jpg');
image3 = imread('office_3.jpg');
image4 = imread('office_4.jpg');
image5 = imread('office_5.jpg');
image6 = imread('office_6.jpg');

Create a cell array of LDR images in the workspace by using the cell construction operation, { }.

images = {image1,image2,image3,image4,image5,image6};

Display the images as a montage.

montage(images)

Figure contains an axes object. The hidden axes object contains an object of type image.

Specify the exposure value for each LDR image in the input cell array.

exposure = [0.0333 0.1000 0.3333 0.6250 1.3000 4.0000];

Compute the relative exposure values with respect to the exposure value of the first LDR image in the input cell array.

relExposure = exposure./exposure(1);

Combine the LDR images into an HDR image. Specify the relative exposure values for each image in the cell array.

hdr = makehdr(images,'RelativeExposure',relExposure);

Display the HDR image.

rgb = tonemap(hdr);
imshow(rgb)

Figure contains an axes object. The hidden axes object contains an object of type image.

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.

Set of spatially registered LDR images, specified as a cell array. 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 Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

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.

  • You must not specify 'BaseFile' name-value pair, when the input is a cell array of spatially registered LDR images.

Exposure value of each image 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 image 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.

Version History

Introduced in R2008a