Permalink
Browse files

Finish AlbedoDeltaAccumulator tests

There exists tests for all the albedo accumulators now. It also fixed a bug with the albedo.
  • Loading branch information...
1 parent 329b687 commit a0c92f09e6c8817d3bfd9363249791298dabf0bf Zack Moratto committed May 11, 2010
Showing with 96 additions and 2 deletions.
  1. +12 −2 src/asp/PhotometryTK/AlbedoAccumulators.h
  2. +84 −0 src/asp/PhotometryTK/tests/TestAlbedoAccumulators.cxx
@@ -87,14 +87,16 @@ namespace pho {
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_t_grad(cols,rows), m_t_error(cols,rows), m_sum_weight(cols,rows) {
this->reset();
}
@@ -111,12 +113,15 @@ namespace pho {
// 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;
}
@@ -129,14 +134,16 @@ namespace pho {
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_t_error( cols, rows ), m_sum_weight( cols, rows ) {
this->reset(); // OCD
}
@@ -151,12 +158,15 @@ namespace pho {
// 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;
}
@@ -164,10 +164,94 @@ TEST_F( AlbedoAccumulatorTestFloat, AlbedoInitNR ) {
}
TEST_F( AlbedoAccumulatorTestInt, AlbedoDelta ) {
+ typedef PixelGrayA<uint8> Px;
+ AlbedoDeltaAccumulator<Px > accu(2,2);
+ typedef AlbedoDeltaAccumulator<Px >::result_type result_type;
+ result_type null = accu.result();
+ EXPECT_IMAGE_NULL( Px, null );
+
+ // Accumulate one image
+ accu( image, albedo, reflectance, exposure_t );
+ result_type result = accu.result();
+ EXPECT_PIXEL_EQ( Px(0,255), result(0,0) );
+ EXPECT_PIXEL_EQ( Px(255,255), result(0,1) ); // Integer wrap
+ EXPECT_PIXEL_EQ( Px(), result(1,0) );
+ EXPECT_PIXEL_EQ( Px(255,255), result(1,1) ); // Integer wrap
+
+ null = accu.result();
+ EXPECT_IMAGE_NULL( Px, null );
+
+ // Accumulate two images
+ accu( image, albedo, reflectance, exposure_t );
+ accu( image2, albedo, reflectance2, exposure_t2 );
+ result = accu.result();
+ EXPECT_PIXEL_EQ( Px(0,255), result(0,0) );
+ EXPECT_PIXEL_EQ( Px(0,255), result(0,1) );
+ EXPECT_PIXEL_EQ( Px(0,255), result(1,0) );
+ EXPECT_PIXEL_EQ( Px(254,255), result(1,1) );
+
+ null = accu.result();
+ EXPECT_IMAGE_NULL( Px, null );
}
TEST_F( AlbedoAccumulatorTestFloat, AlbedoDelta ) {
+ typedef PixelGrayA<float> Px;
+ AlbedoDeltaAccumulator<Px > accu(2,2);
+ typedef AlbedoDeltaAccumulator<Px >::result_type result_type;
+ result_type null = accu.result();
+ EXPECT_IMAGE_NULL( Px, null );
+
+ // Accumulate one image
+ accu( image, albedo, reflectance, exposure_t );
+ result_type result = accu.result();
+ EXPECT_PIXEL_EQ( Px(0,1), result(0,0) );
+ EXPECT_PIXEL_EQ( Px(-1,1), result(0,1));
+ EXPECT_PIXEL_EQ( Px(), result(1,0) );
+ EXPECT_PIXEL_EQ( Px(-1,1), result(1,1));
+
+ null = accu.result();
+ EXPECT_IMAGE_NULL( Px, null );
+
+ // Accumulate two images
+ accu( image, albedo, reflectance, exposure_t );
+ accu( image2, albedo, reflectance2, exposure_t2 );
+ result = accu.result();
+ EXPECT_PIXEL_EQ( Px(0,1), result(0,0) );
+ EXPECT_PIXEL_NEAR( Px(-0.225806,1), result(0,1), 1e-6 );
+ EXPECT_PIXEL_NEAR( Px(-0.222222,1), result(1,0), 1e-6 );
+ EXPECT_PIXEL_NEAR( Px(-2.153846,1), result(1,1), 1e-6 );
+
+ null = accu.result();
+ EXPECT_IMAGE_NULL( Px, null );
}
TEST_F( AlbedoAccumulatorTestFloat, AlbedoDeltaNR ) {
+ typedef PixelGrayA<float> Px;
+ AlbedoDeltaNRAccumulator<Px > accu(2,2);
+ typedef AlbedoDeltaNRAccumulator<Px >::result_type result_type;
+ result_type null = accu.result();
+ EXPECT_IMAGE_NULL( Px, null );
+
+ // Accumulate one image
+ accu( image, albedo, exposure_t );
+ result_type result = accu.result();
+ EXPECT_PIXEL_EQ( Px(0,1), result(0,0) );
+ EXPECT_PIXEL_EQ( Px(-1,1), result(0,1) );
+ EXPECT_PIXEL_EQ( Px(), result(1,0) );
+ EXPECT_PIXEL_EQ( Px(1,1), result(1,1) );
+
+ null = accu.result();
+ EXPECT_IMAGE_NULL( Px, null );
+
+ // Accumulate two images
+ accu( image, albedo, exposure_t );
+ accu( image2, albedo, exposure_t2 );
+ result = accu.result();
+ EXPECT_PIXEL_NEAR( Px(1.384615,1), result(0,0), 1e-6 );
+ EXPECT_PIXEL_NEAR( Px(1.322581,1), result(0,1), 1e-6 );
+ EXPECT_PIXEL_NEAR( Px(3.333333,1), result(1,0), 1e-6 );
+ EXPECT_PIXEL_NEAR( Px(0.04, 1), result(1,1), 1e-6 );
+
+ null = accu.result();
+ EXPECT_IMAGE_NULL( Px, null );
}

0 comments on commit a0c92f0

Please sign in to comment.