Why am I getting an error when I use grayscale images with "makehdr"in Image Processing Toolbox 8.1 (R2012b)? I am receiving the following error when trying to use the "makehdr" utility. low dynamic images must be RGB I suspect the reason is that my images are black-and-white. Is there any workaround for this issue?
Prashant Kumar answered .
2025-11-20
% Step 1 - Load grayscale image
imGray = imread('grayscaleImage.tif');
% Step 2 - Replicate image into RGB layers using REPMAT
nRV = 1; % Number Of Replications Vertically
nRH = 1; % Number Of Replications Horizontally
nRL = 3; % Number Of Replication Layers
imRGB = repmat(imGray,[nRV, nRH, nRL]); % Replicate grayscale image 3 times
% Step 3 - Write resized image to file
imageName = 'rgbImage.tif';
imwrite(imRGB,imageName)
% Step 4 - Generate HDR from TIF File
imageNames = {imageName}; % MAKEHDR uses a cell array of strings as input.
RE = 1; % Currently a scalar, but would be a matrix for multiple images.
imHDR = makehdr(imageNames,'RelativeExposure',RE); % Create HDR image.
% Step 5 - Display image
imLDR = tonemap(imHDR); % Create LDR image from HDR image for display purposes.
figure; imshow(imLDR) % Display LDR image.
2. Use CAT to concatenate the 2D image 3 times
% Step 2 - Concatenate image into RGB layers using CAT nRL = 3; % Number Of Replication Layers imRGB = cat(nRL,grayImage,grayImage,grayImage);