一种简单的用于显示HDR的色调映射方法
Posted keven-lee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一种简单的用于显示HDR的色调映射方法相关的知识,希望对你有一定的参考价值。
来源于论文 “Fast Bilateral Filtering for the Display of High-Dynamic-Range Images”
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 % Author: KevenLee 3 % Contact: [email protected].com 4 % Date: 20180828 5 % Version: V1.0.0 6 % Description: matlab code for simple tonemapping 7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 9 clear 10 clc 11 close all 12 13 if(~exist(‘memorial.hdr‘)) 14 I = double(hdrread(‘office.hdr‘)); 15 else 16 I = double(hdrread(‘memorial.hdr‘)); 17 end 18 19 % intensity and r, g, b channel 20 intensity = 0.299 * I(:,:,1) + 0.587 * I(:,:,2) + 0.114 * I(:,:,3); 21 22 mask = (intensity == 0); 23 intensity = intensity.*(1-mask) + (intensity.*mask+mask.*1); 24 25 r = I(:,:,1)./intensity; 26 g = I(:,:,2)./intensity; 27 b = I(:,:,3)./intensity; 28 29 logIntensity = log10(intensity); 30 31 if(0) 32 logBase=bilateralFilter(logIntensity, [], 0, 1.0, 3, 25); 33 else 34 % you can using guidefilter here, which would be faster. 35 logBase = imguidedfilter(logIntensity,‘NeighborhoodSize‘,[3 3],‘DegreeOfSmoothing‘,0.1); 36 end 37 % details in log10 domain 38 logDetail = logIntensity - logBase; 39 40 % compression factor. log10(5) for default. You can modify it. visually, larger 41 % darker, smaller lighter 42 compressionfactor = log10(5)/(max(logBase(:)) - min(logBase(:))); 43 log_absolute_scale= max(logBase(:))*compressionfactor; 44 45 logOutIntensity = logBase.*compressionfactor + logDetail - log_absolute_scale; 46 47 % adjust every channel. 48 routput = r.*10.^(logOutIntensity); 49 goutput = g.*10.^(logOutIntensity); 50 boutput = b.*10.^(logOutIntensity); 51 52 % output image 53 OI = cat(3, routput,goutput,boutput); 54 55 % you can add some operators here. etc. color balance 56 output = uint8(OI.*255); 57 58 % saving as 8-bits jpg image 59 imwrite(output, ‘tonemapping.jpg‘); 60 imwrite(I, ‘hdr.jpg‘); 61 62 figure(‘Name‘, ‘hdr image‘),imshow(uint8(I)),title(‘hdr image‘) 63 figure(‘Name‘, ‘toneMapping‘),imshow(output),title(‘toneMapping‘)
具体结果如下,左边是线性压缩到8bit的图像,右图是tonemap后的图像。
参考
https://www.cnblogs.com/Imageshop/p/3428809.html
以上是关于一种简单的用于显示HDR的色调映射方法的主要内容,如果未能解决你的问题,请参考以下文章