{"id":9791,"date":"2018-06-01T09:00:42","date_gmt":"2018-06-01T13:00:42","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=9791"},"modified":"2018-06-01T09:44:12","modified_gmt":"2018-06-01T13:44:12","slug":"the-hdr-toolbox","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2018\/06\/01\/the-hdr-toolbox\/","title":{"rendered":"The HDR Toolbox"},"content":{"rendered":"<div class=\"content\">\n<p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/4604835\">Sebastian<\/a>&#8216;s pick this week is <a href=\"https:\/\/www.mathworks.com\/\/matlabcentral\/fileexchange\/67248\">The HDR Toolbox<\/a> by <a href=\"https:\/\/www.mathworks.com\/\/matlabcentral\/profile\/authors\/7463679\">Francesco Banterle<\/a>.<\/p>\n<p><i>Sebastian is a Senior Customer Success Engineer at MathWorks&#8217; Munich office.<\/i><\/p>\n<p>Hello everyone,<\/p>\n<p>My name is Sebastian and I work directly with our academic customers in research and teaching. As such, I have the pleasure to get to know many fascinating projects and meet interesting people. One of these projects is HDR Toolbox which was recently made available on File Exchange. However, the sources of the project have been growing since 2008.<\/p>\n<p>With High Dynamic Range (HDR) imaging you can create <a href=\"https:\/\/de.wikipedia.org\/wiki\/High_Dynamic_Range_Image#\/media\/File:New_York_City_at_night_HDR.jpg\">spectacular scenes<\/a> by combining multiple pictures of the same scene. The pictures are usually create using different exposure times, so they contain varying information. This information can be remapped to ensure that all areas of the output image are properly visible.<\/p>\n<p>My first contact with this technology happened during my time as a researcher at the Institute of Image Processing and Computer Vision at RWTH Aachen University. My colleague Johannes had a research project in the area of <a href=\"http:\/\/www.lfb.rwth-aachen.de\/wp-content\/plugins\/bibtex\/show_pdf.php?file=BRA08a.pdf\">Multispectral High Dynamic Range Imaging<\/a> and I was naturally intrigued to look at the toolbox.<\/p>\n<p>I used the GitHub link to download the toolbox and ran \u2018installHDRToolbox.m\u2019.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHDRTbx\/install.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>Installation went smoothly for me.<\/p>\n<p>The toolbox comes with several demo files, so I changed into the \u2018Demos\u2019 directory and inspected the first example \u2018demo_build_hdr.m\u2019.<br \/>\nIt uses the images in the \u2018stack\u2019 directory. You can view them with this code:<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">figure\r\n<span style=\"color: #0000ff;\">for<\/span> i = 0:5\r\n    subplot(2,3,i+1)\r\n    imshow(imread([<span style=\"color: #a020f0;\">'stack\\stack_room_exp_'<\/span> num2str(i) <span style=\"color: #a020f0;\">'.jpg'<\/span>]))\r\n<span style=\"color: #0000ff;\">end<\/span><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHDRTbx\/montage.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>The result of script \u2018demo_build_hdr.m\u2019 clearly illustrates the combined information in the output image. A lot more details are visible than in any of the individual images.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHDRTbx\/detail.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>While creating the source images with different exposure settings, you might introduce another challenge which is illustrated in a different dataset.<\/p>\n<p>I used a different dataset (\u2018stack alignment\u2019) and created this image with the script \u2018demo_build_hdr.m\u2019.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHDRTbx\/blurry.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>Now, the HDR part seems to have worked, but this looks all blurry.<\/p>\n<p>If you run:<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">figure\r\n\r\nimg1 = imread(<span style=\"color: #a020f0;\">'stack_alignment\\IMG_4211.jpg'<\/span>);\r\nimg2 = imread(<span style=\"color: #a020f0;\">'stack_alignment\\IMG_4209.jpg'<\/span>);\r\nimg3 = imread(<span style=\"color: #a020f0;\">'stack_alignment\\IMG_4210.jpg'<\/span>);\r\n\r\nsubplot(3,1,1)\r\nimshow(img1)\r\nsubplot(3,1,2)\r\nimshow(img2)\r\nsubplot(3,1,3)\r\nimshow(img3)<\/pre>\n<p>you can take a look at the images.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHDRTbx\/montage2.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>So far, they do not clearly indicate the problem. If, however, you combine parts of them, you can see it clearly. (This is not directly similar to what would happen if you used the HDR algorithm, but it has the same challenges.)<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">figure\r\n\r\nimg_cmp = [img1(1:360,:,:); img2(361:720,:,:); img3(721:1080,:,:)];\r\nimshow(img_cmp)<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHDRTbx\/stacked.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHDRTbx\/zoomed.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>The images are not properly aligned. This will cause problems in the HDR algorithm. \u2018demo_build_hdr_sift_alignment\u2019 gives a<br \/>\ndemonstration of how to use alignment with SIFT (Scale Invariant Feature Transform) to overcome this challenge. This requires the installation of vl_feat (<a href=\"http:\/\/www.vlfeat.org\/\">http:\/\/www.vlfeat.org\/<\/a>).<\/p>\n<p>So, running this, the output image is cleanly aligned and the HDR algorithm worked.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHDRTbx\/final.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>There are several other demos to give you additional insight. If you want to know more about HDR, you should check out the HDR Toolbox authors\u2019 book &#8220;<a href=\"http:\/\/www.advancedhdrbook.com\/\">Advanced High Dynamic Range Imaging: Theory and Practice<\/a>&#8221; which features the toolbox and a lot more information.<\/p>\n<p>Or, you jump right in and try it. Why don\u2019t you get your DSLR from the shelf and take a series of photos? I would love to hear from you how things are going.<\/p>\n<p>In any case, have a lot of fun.<\/p>\n<p>Sebastian<\/p>\n<h3>Comments<a name=\"6\"><\/a><\/h3>\n<p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=9791#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/\/matlabcentral\/fileexchange\/67248#comments\">comment<\/a> for Francesco.<\/p>\n<p><script language=\"JavaScript\">\n<!--\n\n    function grabCode_c0f816b9eae843a6b6059420c052bc3c() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='c0f816b9eae843a6b6059420c052bc3c ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' c0f816b9eae843a6b6059420c052bc3c';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Sebastian Gross';\n        copyright = 'Copyright 2018 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\n<\/p>\n\n\n\n\n<p>\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }   \n      \n-->\n<\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\"><a><span style=\"font-size: x-small; font-style: italic;\">Get<br \/>\nthe MATLAB code<br \/>\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>Published with MATLAB\u00ae R2018a<\/p>\n<\/div>\n<p><!--\nc0f816b9eae843a6b6059420c052bc3c ##### SOURCE BEGIN #####\n%% The HDR Toolbox\n%\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/4604835 Sebastian>'s pick this week is\n% <https:\/\/www.mathworks.com\/\/matlabcentral\/fileexchange\/67248 The HDR Toolbox> by\n% <https:\/\/www.mathworks.com\/\/matlabcentral\/profile\/authors\/7463679 Francesco Banterle>.\n%\n% _Sebastian is a Senior Customer Success Engineer at MathWorks' Munich\n% office._\n\n%%\n% Hello everyone,\n%\n% My name is Sebastian and I work directly with our academic customers in\n% research and teaching. As such, I have the pleasure to get to know many\n% fascinating projects and meet interesting people. One of these projects\n% is HDR Toolbox which was recently made available on File Exchange.\n% However, the sources of the project have been growing since 2008.\n%\n% High Dynamic Range (HDR) imaging can create\n% <https:\/\/de.wikipedia.org\/wiki\/High_Dynamic_Range_Image#\/media\/File:New_York_City_at_night_HDR.jpg % spectacular scenes> by combining images of different exposure time of the\n% same scene. As such, image information can be remapped to ensure that\n% areas are not over- or underexposed on an individual image. My first\n% contact with this technology happened during my time as a researcher at\n% the Institute of Image Processing and Computer Vision at RWTH Aachen\n% University. My colleague Johannes had a research project in the area of\n% <http:\/\/www.lfb.rwth-aachen.de\/wp-content\/plugins\/bibtex\/show_pdf.php?file=BRA08a.pdf % Multispectral High Dynamic Range Imaging> and I was naturally intrigued\n% to look at the toolbox.\n%\n% I used the GitHub link to download the toolbox and ran \u00e2\u20ac\u02dcinstallHDRToolbox.m\u00e2\u20ac&#x2122;.\n%\n% <<install.png>>\n\n%%\n% Installation went smoothly for me.\n%\n% The toolbox comes with several demo files, so I changed into the \u00e2\u20ac\u02dcDemos\u00e2\u20ac&#x2122;\n% directory and inspected the first example \u00e2\u20ac\u02dcdemo_build_hdr.m\u00e2\u20ac&#x2122;. It uses the\n% images in the \u00e2\u20ac\u02dcstack\u00e2\u20ac&#x2122; directory. You can view them with this code:\n\nfigure\nfor i = 0:5\nsubplot(2,3,i+1)\nimshow(imread(['stack\\stack_room_exp_' num2str(i) '.jpg']))\nend\n\n%%\n%\n% <<montage.png>>\n%\n% The result of script \u00e2\u20ac\u02dcdemo_build_hdr.m\u00e2\u20ac&#x2122; clearly illustrates the combined\n% information in the output image. A lot more details are visible than in\n% any of the individual images.\n%\n% <<detail.png>>\n%\n% While creating the source images with different exposure settings, you\n% might introduce another challenge which is illustrated in a different\n% dataset.\n%\n% I used a different dataset (\u00e2\u20ac\u02dcstack alignment\u00e2\u20ac&#x2122;) and created this image\n% with the script \u00e2\u20ac\u02dcdemo_build_hdr.m\u00e2\u20ac&#x2122;.\n%\n% <<blurry.png>>\n%\n% Now, the HDR part seems to have worked, but this looks all blurry.\n%\n% If you run:\n\nfigure\n\nimg1 = imread('stack_alignment\\IMG_4211.jpg');\nimg2 = imread('stack_alignment\\IMG_4209.jpg');\nimg3 = imread('stack_alignment\\IMG_4210.jpg');\n\nsubplot(3,1,1)\nimshow(img1)\nsubplot(3,1,2)\nimshow(img2)\nsubplot(3,1,3)\nimshow(img3)\n\n%%\n% you can take a look at the images.\n%\n% <<montage2.png>>\n%\n% So far, they do not clearly indicate the problem. If, however, you\n% combine parts of them, you can see it clearly. (This is not directly\n% similar to what would happen if you used the HDR algorithm, but it has\n% the same challenges.)\n\nfigure\n\nimg_cmp = [img1(1:360,:,:); img2(361:720,:,:); img3(721:1080,:,:)];\nimshow(img_cmp)\n\n%%\n%\n% <<stacked.png>>\n%\n% <<zoomed.png>>\n%\n% The images are not properly aligned. This will cause problems in the HDR\n% algorithm. \u00e2\u20ac\u02dcdemo_build_hdr_sift_alignment\u00e2\u20ac&#x2122; give a demonstration of how to\n% use alignment with SIFT (Scale Invariant Feature Transform) to overcome\n% this challenge. This requires the installation of vl_feat\n% (<http:\/\/www.vlfeat.org\/>).\n%\n% So, running this, the output image is cleanly aligned and HDR.\n%\n% <<final.png>>\n%\n% There are several other demos to give you additional insight. If you want\n% to know more about HDR, you should check out the HDR Toolbox authors\u00e2\u20ac&#x2122;\n% book \" <http:\/\/www.advancedhdrbook.com\/ Advanced High Dynamic Range Imaging: Theory and Practice> \" which\n% features the toolbox and a lot more information.\n%\n% Or, you jump right in and try it. How about getting your DSLR from the shelve and take a series of photos. I would love to hear from you how things are going.\n%\n% In any case, have a lot of fun.\n%\n% Sebastian\n\n%% Comments\n%\n% Give it a try and let us know what you think\n% <https:\/\/blogs.mathworks.com\/pick\/?p=9791#respond here> or leave a\n% <https:\/\/www.mathworks.com\/\/matlabcentral\/fileexchange\/67248#comments % comment> for Francesco.\n%\n\n##### SOURCE END ##### c0f816b9eae843a6b6059420c052bc3c\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/final.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>\nSebastian&#8216;s pick this week is The HDR Toolbox by Francesco Banterle.<br \/>\nSebastian is a Senior Customer Success Engineer at MathWorks&#8217; Munich office.<br \/>\nHello everyone,<br \/>\nMy name is Sebastian and&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2018\/06\/01\/the-hdr-toolbox\/\">read more >><\/a><\/p>\n","protected":false},"author":36,"featured_media":9811,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9791"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=9791"}],"version-history":[{"count":9,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9791\/revisions"}],"predecessor-version":[{"id":9819,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/9791\/revisions\/9819"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/9811"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=9791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=9791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=9791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}