/** * @file tmo_bilateral.cpp * @brief Local tone mapping operator based on bilateral filtering. * Durand et al. 2002 * * Fast Bilateral Filtering for the Display of High-Dynamic-Range Images. * F. Durand and J. Dorsey. * In ACM Transactions on Graphics, 2002. * * * This file is a part of PFSTMO package. * ---------------------------------------------------------------------- * Copyright (C) 2003,2004 Grzegorz Krawczyk * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ---------------------------------------------------------------------- * * @author Grzegorz Krawczyk, * * $Id: tmo_durand02.cpp,v 1.1 2007/06/14 16:41:30 gkrawczyk Exp $ */ #include #include #include #include #include #include #ifdef HAVE_FFTW3F #include "fastbilateral.h" #else #include "bilateral.h" #endif void findMaxMinPercentile(pfs::Array2D* I, float minPrct, float& minLum, float maxPrct, float& maxLum); /* From Durand's webpage: Here is the high-level set of operation that you need to do in order to perform contrast reduction input intensity= 1/61*(R*20+G*40+B) r=R/(input intensity), g=G/input intensity, B=B/input intensity log(base)=Bilateral(log(input intensity)) log(detail)=log(input intensity)-log(base) log (output intensity)=log(base)*compressionfactor+log(detail) R output = r*exp(log(output intensity)), etc. */ void tmo_durand02(pfs::Array2D *R, pfs::Array2D *G, pfs::Array2D *B, float sigma_s, float sigma_r, float baseContrast, int downsample ) { int i; int w = R->getCols(); int h = R->getRows(); int size = w*h; pfs::Array2D* I = new pfs::Array2DImpl(w,h); // intensities pfs::Array2D* BASE = new pfs::Array2DImpl(w,h); // base layer pfs::Array2D* DETAIL = new pfs::Array2DImpl(w,h); // detail layer for( i=0 ; i