/
pfstmo_mantiuk06.cpp
106 lines (90 loc) · 3.19 KB
/
pfstmo_mantiuk06.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* @brief Contrast mapping TMO
*
* From:
*
* Rafal Mantiuk, Karol Myszkowski, Hans-Peter Seidel.
* A Perceptual Framework for Contrast Processing of High Dynamic Range Images
* In: ACM Transactions on Applied Perception 3 (3), pp. 286-308, 2006
* http://www.mpi-inf.mpg.de/~mantiuk/contrast_domain/
*
* This file is a part of LuminanceHDR package, based on pfstmo.
* ----------------------------------------------------------------------
* Copyright (C) 2007 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 Radoslaw Mantiuk, <radoslaw.mantiuk@gmail.com>
* @author Rafal Mantiuk, <mantiuk@gmail.com>
* Updated 2007/12/17 by Ed Brambley <E.J.Brambley@damtp.cam.ac.uk>
*
* $Id: pfstmo_mantiuk06.cpp,v 1.9 2008/06/16 22:09:33 rafm Exp $
*/
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include "contrast_domain.h"
#include "Libpfs/pfs.h"
#include "Libpfs/frame.h"
#include "Libpfs/colorspace/colorspace.h"
//--- default tone mapping parameters;
// float scaleFactor = 0.1f;
// float saturationFactor = 0.8f;
// bool cont_map = false, cont_eq = false
// bool cont_map = false;
namespace
{
const int itmax = 200;
const float tol = 5e-3f;
}
void pfstmo_mantiuk06(pfs::Frame& frame, float scaleFactor,
float saturationFactor, float detailFactor,
bool cont_eq, pfs::Progress &ph)
{
#ifndef NDEBUG
std::stringstream ss;
ss << "pfstmo_mantiuk06 (";
if (!cont_eq)
{
ss << "Mode: Contrast Mapping, ";
}
else
{
scaleFactor = -scaleFactor;
ss << "Mode: Contrast Equalization, ";
}
ss << "scaleFactor: " << scaleFactor;
ss << ", saturationFactor: " << saturationFactor;
ss << ", detailFactor: " << detailFactor << ")" << std::endl;
std::cout << ss.str();
#endif
pfs::Channel *inRed, *inGreen, *inBlue;
frame.getXYZChannels(inRed, inGreen, inBlue);
if ( !inRed || !inGreen || !inBlue )
{
throw pfs::Exception( "Missing X, Y, Z channels in the PFS stream" );
}
const int cols = frame.getWidth();
const int rows = frame.getHeight();
pfs::Array2Df inY( cols, rows );
pfs::transformRGB2Y(inRed, inGreen, inBlue, &inY);
tmo_mantiuk06_contmap(*inRed, *inGreen, *inBlue, inY,
scaleFactor, saturationFactor, detailFactor, itmax, tol,
ph);
frame.getTags().setTag("LUMINANCE", "RELATIVE");
}