/
AlbedoAccumulators.h
177 lines (157 loc) · 6.33 KB
/
AlbedoAccumulators.h
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#ifndef __ASP_PHO_ALBEDO_ACCUMULATORS_H__
#define __ASP_PHO_ALBEDO_ACCUMULATORS_H__
#include <asp/PhotometryTK/ImageAccumulators.h>
#include <vw/Image/ImageView.h>
#include <vw/Image/Algorithms.h>
namespace asp {
namespace pho {
template <class PixelT>
class AlbedoInitAccumulator : public ImageAccumulatorBase<AlbedoInitAccumulator<PixelT> > {
typedef typename vw::CompoundChannelCast<PixelT, double>::type accum_pixel_type;
typedef typename vw::PixelChannelType<PixelT>::type channel_type;
vw::ImageView<accum_pixel_type> m_sum;
vw::ImageView<double> m_sum_weight;
void reset( void ) {
vw::fill(m_sum, accum_pixel_type() );
vw::fill(m_sum_weight, 0 );
}
public:
AlbedoInitAccumulator( vw::int32 const& cols, vw::int32 const& rows ) :
m_sum(cols,rows), m_sum_weight(cols,rows) {
this->reset();
}
// Accumulate
template <class IViewT, class RViewT>
void operator()( vw::ImageViewBase<IViewT> const& image,
vw::ImageViewBase<RViewT> const& reflectance,
double const& t ) {
m_sum_weight += select_channel(image.impl(),1);
m_sum += select_channel(image.impl(),0)*select_channel(image.impl(),1) /
( t*reflectance.impl() );
}
// Result
typedef vw::ImageView<PixelT> result_type;
result_type result(void) {
// Normalize
result_type r = m_sum/m_sum_weight;
// Apply alpha
select_channel(r,1) = vw::channel_cast_rescale<channel_type>(threshold(m_sum_weight,0));
this->reset();
return r;
}
};
template <class PixelT>
class AlbedoInitNRAccumulator : public ImageAccumulatorBase<AlbedoInitNRAccumulator<PixelT> > {
typedef typename vw::CompoundChannelCast<PixelT, double>::type accum_pixel_type;
typedef typename vw::PixelChannelType<PixelT>::type channel_type;
vw::ImageView<accum_pixel_type> m_sum;
vw::ImageView<double> m_sum_weight;
void reset( void ) {
vw::fill(m_sum, accum_pixel_type() );
vw::fill(m_sum_weight, 0 );
}
public:
AlbedoInitNRAccumulator( vw::int32 const& cols, vw::int32 const& rows ) :
m_sum(cols,rows), m_sum_weight(cols,rows) {
this->reset();
}
// Accumulate
template <class IViewT>
void operator()( vw::ImageViewBase<IViewT> const& image,
double const& t ) {
m_sum_weight += select_channel(image.impl(),1);
m_sum += select_channel(image.impl(),0)*select_channel(image.impl(),1) / t;
}
// Result
typedef vw::ImageView<PixelT> result_type;
result_type result(void) {
result_type r = m_sum/m_sum_weight;
select_channel(r,1) = vw::channel_cast_rescale<channel_type>(threshold(m_sum_weight,0));
this->reset();
return r;
}
};
template <class PixelT>
class AlbedoDeltaAccumulator : public ImageAccumulatorBase<AlbedoDeltaAccumulator<PixelT> > {
typedef typename vw::CompoundChannelCast<PixelT, double>::type accum_pixel_type;
typedef typename vw::PixelChannelType<PixelT>::type channel_type;
vw::ImageView<accum_pixel_type> m_nominator, m_denominator;
vw::ImageView<accum_pixel_type> m_t_grad, m_t_error; // temporaries to avoid
// excessive memory allocations.
vw::ImageView<double> m_sum_weight;
void reset( void ) {
vw::fill(m_nominator, accum_pixel_type() );
vw::fill(m_denominator, accum_pixel_type() );
vw::fill(m_sum_weight, 0 );
}
public:
AlbedoDeltaAccumulator( vw::int32 const& cols, vw::int32 const& rows ) :
m_nominator(cols,rows), m_denominator(cols,rows),
m_t_grad(cols,rows), m_t_error(cols,rows), m_sum_weight(cols,rows) {
this->reset();
}
// Accumulate
template <class IViewT, class AViewT, class RViewT>
void operator()( vw::ImageViewBase<IViewT> const& image,
vw::ImageViewBase<AViewT> const& previous_albedo,
vw::ImageViewBase<RViewT> const& reflectance,
double const& t ) {
// Intermediates
m_t_grad = t * reflectance;
m_t_error = select_channel(image,0) - t * previous_albedo * reflectance;
// Update accumulators
m_nominator += m_t_grad * m_t_error * select_channel(image,1);
m_denominator += m_t_grad * m_t_grad * select_channel(image,1);
m_sum_weight += select_channel(image,1);
}
// Result
typedef vw::ImageView<PixelT> result_type;
result_type result(void) {
result_type r = m_nominator / m_denominator;
select_channel(r,1) = vw::channel_cast_rescale<channel_type>(threshold(m_sum_weight,0));
this->reset();
return r;
}
};
template <class PixelT>
class AlbedoDeltaNRAccumulator : public ImageAccumulatorBase<AlbedoDeltaNRAccumulator<PixelT> > {
typedef typename vw::CompoundChannelCast<PixelT, double>::type accum_pixel_type;
typedef typename vw::PixelChannelType<PixelT>::type channel_type;
vw::ImageView<PixelT> m_nominator, m_denominator;
vw::ImageView<PixelT> m_t_error; // temporary to avoid
// excessive memory allocations.
vw::ImageView<double> m_sum_weight;
void reset( void ) {
vw::fill(m_nominator, PixelT() );
vw::fill(m_denominator, PixelT() );
vw::fill(m_sum_weight, 0 );
}
public:
AlbedoDeltaNRAccumulator( vw::int32 const& cols, vw::int32 const& rows ) :
m_nominator( cols, rows ), m_denominator( cols, rows ),
m_t_error( cols, rows ), m_sum_weight( cols, rows ) {
this->reset(); // OCD
}
// Accumulate
template <class IViewT, class AViewT>
void operator()( vw::ImageViewBase<IViewT> const& image,
vw::ImageViewBase<AViewT> const& previous_albedo,
double const& t ) {
// Intermediate
m_t_error = select_channel(image,0) - t*previous_albedo;
// Update accumulators
m_nominator += t * m_t_error * select_channel(image,1);
m_denominator += t * t * select_channel(image,1);
m_sum_weight += select_channel(image,1);
}
// Result
typedef vw::ImageView<PixelT> result_type;
result_type result(void) {
result_type r = m_nominator / m_denominator;
select_channel(r,1) = vw::channel_cast_rescale<channel_type>(threshold(m_sum_weight,0));
this->reset();
return r;
}
};
}} // end namespace asp::pho
#endif//__ASP_PHO_ALBEDO_ACCUMULATORS_H__