Is it possible to use the makehdr MATLAB function with 16bit images?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I would like to create an grayscale HDR image. The files are in tiff format. Before I use the makehdr function I convert the grayscale images to 16bit rgb images.
But when I want to apply the makehdr function I get the error:
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in makehdr (line 147)
hdr(someOverExposed & ~someUnderExposed & ~someProperlyExposed) = max(hdr(someProperlyExposed));
I start with loading the images:
low_1 = imread(strcat(path,'low\low_1.tif'));
Then I convert them to RGB:
[m n]=size(low_1);
rgb_low_1=zeros(m,n,3);
rgb_low_1(:,:,1)=low_1;
rgb_low_1(:,:,2)=rgb_low_1(:,:,1);
rgb_low_1(:,:,3)=rgb_low_1(:,:,1);
Then I convert them to uint16 before I save them with imwrite in order to keep the 16bit:
rgb_low_1_int16 = uint16(rgb_low_1);
imwrite(rgb_low_1_int16,strcat(path,'low\rgb_low_1_int16.tif'));
And then I start the function with:
expTimes = [0.0333, 0.1000, 0.3333];
hdr_files_rgb = {strcat(path,'low\rgb_low_1_int16.tif'),...
strcat(path,'medium\rgb_medium_1_int16.tif'),...
strcat(path,'high\rgb_high_1_int16.tif')};
hdr_file = makehdr(hdr_files_rgb, 'RelativeExposure', expTimes ./ expTimes(1));
But then I got the Error mentioned above. If I do the same thing but with 8bit files it works flawlessly but I do not want to lose image information.
Could anyone give me some advise what might be the issue here? Thank you so much for your help!
1 comentario
Robert Bosh
el 8 de Jun. de 2016
Having this exact same problem. Using a method nearly identical to this and having the same error message. Any help would be appreciated. Thanks!
Respuestas (1)
DGM
el 7 de Sept. de 2024
This appears to have been a bug in makehdr(). As usual, it doesn't appear anywhere in bug reports, but starting somewhere around 2018, that section of code has been fixed to catch cases where the RHS of the assignment becomes empty.
Consider the proof scenario:
%% Generate some gray uint16 test images
% replicate OP's test files
files = {'office_1.jpg','office_4.jpg','office_6.jpg'}; % IPT demo images
for k = 1:numel(files)
inpict = imread(files{k}); % read an image (uint8, RGB)
outpict = im2gray(inpict); % OP's images are grayscale, so make it gray
outpict = repmat(outpict,[1 1 3]); % expand it to RGB
outpict = im2uint16(outpict); % rescale it to uint16
imwrite(outpict,sprintf('office_%d.png',k)) % write it
end
%% Compose and tonemap the new test images
files = {'office_1.png','office_2.png','office_3.png'};
expTimes = [0.0333 0.6250 4.0000];
hdr = makehdr(files,'RelativeExposure',expTimes./expTimes(1));
rgb = tonemap(hdr);
% show it
imshow(rgb)
This example works in R2024a and R2019b, but it fails with the same error reported above in R2015b.
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!