Make HDR from 3D matrix

11 views (last 30 days)
Luka Rogelj
Luka Rogelj on 30 Jan 2020
Hi! I would like to make HDR image from grayscale images. I have my grayscale images data in 3D matrix (two dimentions are spatial and one dimention is exposure time)? I wanted to do this with makehdr function I did not succed.
Thank you!
  1 Comment
Vinai Datta Thatiparthi
Vinai Datta Thatiparthi on 3 Feb 2020
Hey Luka,
Can you share the grayscale image matrices that you talk about in your question? This could help us solve the problem faster.

Sign in to comment.

Answers (2)

Luka Rogelj
Luka Rogelj on 4 Feb 2020
This is the grayscale. 2 dimentions are spatial, and 1 dimention are three different exposure times.
  2 Comments
Vinai Datta Thatiparthi
Vinai Datta Thatiparthi on 13 Feb 2020
Edited: Vinai Datta Thatiparthi on 13 Feb 2020
Hello Luka,
The data that you have provided isn't comprehensible. Your matrix has 3 dimensions, but it's unclear what the data represents. For example, from the question, I understand that the 3rd plane of the 3-dimensional matrix that you shared contains the Exposure Times information. This would mean a 300x480 plane containing the Exposure Time values, which may not be correct.
To be able to use makehdr, you must have a collection of 'n' images of the same scene, captured with different amounts of exposure. Additionally, a row-vector of size [1xn] containing Exposure Values/Relative Exposure can be provided, where the number of elements is the same as the number of images that you work with.
Hope this helps!
Luka Rogelj
Luka Rogelj on 29 Apr 2020
You are right, I needed some time to repair my system. I am attaching a new data. Hopefuly these are alright. I would still like to make hdr image. In the first matrix there are grayscale images and I am also attaching exposure times for these images.
Thank you!

Sign in to comment.


Vinai Datta Thatiparthi
Vinai Datta Thatiparthi on 29 Apr 2020
Hey Luka,
With the new data that you've provided, this piece of code could help you -
load('hdr_example.mat') % Load Data into MATLAB
cellIm = cell(1,size(images,3)); % Create an empty cell-array to store the images
for idx = 1:size(images,3)
cellIm{idx} = images(:,:,idx); % Every element of the cell array is now a [600 x 903] image
end
% Using the function makehdr
hdr = makehdr(cellIm, 'RelativeExposure', exposure ./ exposure(1));
rgb = tonemap(hdr); % Mapping for viewing HDR image
figure; imshow(rgb) % Show the output image
Hope this helps!
  3 Comments
Luka Rogelj
Luka Rogelj on 29 Apr 2020
I tried it and I get this error:
Error using imfinfo (line 105)
Expected FILENAME to be one of these types:
char, string
Instead its type was uint8.
Error in makehdr>getMetaData (line 271)
meta = imfinfo(filename);
Error in makehdr (line 93)
meta = getMetaData(filenames{1});
Error in Untitled3 (line 7)
hdr = makehdr(cellIm, 'RelativeExposure', exposure ./ exposure(1));
Vinai Datta Thatiparthi
Vinai Datta Thatiparthi on 29 Apr 2020
Hey Luka,
The function makehdr was recently improved & updated to accept a cell array of matrices as inputs directly. Previously, customers were required to use imread to load data from files stored on the PC locally, and then use makehdr. You can notice this behaviour in makehdr Documentation.
The block of code that I shared with you previously utilizes this new feature of the makehdr function. I believe that you're using an older version of MATLAB, and that is why you're running into this error.
Possible workarounds:
  • Please update to the latest revision of MATLAB to be able to utilize this new feature
  • Else, you may have to use the function imwrite to recursively save the image data onto your PC. After you've saved these files, you can follow the example available on makehdr Documentation to get your desired outputs.
load('hdr_example.mat') % Load Data into MATLAB
for idx = 1:size(images,3)
% Filename changes for every iteration
filename = strcat('image_', num2str(idx), '.jpg');
% Save images locally
imwrite(images(:,:,idx), filename)
end
% String of filenames
files = ["image_1.jpg", "image_2.jpg", "image_3.jpg", ...
"image_4.jpg", "image_5.jpg", "image_6.jpg"];
% Using the function makehdr
hdr = makehdr(files, 'RelativeExposure', exposure ./ exposure(1));
rgb = tonemap(hdr); % Mapping for viewing HDR image
figure; imshow(rgb) % Show the output image
Hope this helps!

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!