Question
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?
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 26, 2026
"makehdr" works only on RGB images. The workaround for this issue is to convert the grayscale image to an RGB image.
Grayscale images are 2D (m x n) matrices, while RGB images are 3D (m x n x 3) matrices. Therefore one must expand the 2D matrix to fill the 3D matrix. This can be accomplished a couple ways
1. Use REPMAT to replicate the 2D matrix 3 times.
% 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);
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related Image Processing Toolbox Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →