Skip to content

Commit

Permalink
Added subpixel tests
Browse files Browse the repository at this point in the history
Use to make sure that the code still works and we are not receeding in
quality.

Interesting note that these tests have found. Our current Bayes EM
performs worse than Parabola on high slopes. The problem appears to be
Bayes's poorly implemented pyramid code. Removing that makes BayesEM
perform a lot better in the tests, however I'll need to compare with
real data else where.
  • Loading branch information
Zack Moratto committed Sep 20, 2010
1 parent a7858cd commit 96fc037
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -206,6 +206,7 @@ docs/workbook/workbook.toc
/src/vw/Stereo/tests/TestCorrelator
/src/vw/Stereo/tests/TestDisparity
/src/vw/Stereo/tests/TestStereoModel
/src/vw/Stereo/tests/TestSubPixel
/src/vw/tools/ba_test
/src/vw/tools/ba_unit_test_data
/src/vw/tools/bayer
Expand Down
3 changes: 2 additions & 1 deletion src/vw/Stereo/tests/Makefile.am
Expand Up @@ -14,8 +14,9 @@ if MAKE_MODULE_STEREO
TestStereoModel_SOURCES = TestStereoModel.cxx
TestDisparity_SOURCES = TestDisparity.cxx
TestCorrelator_SOURCES = TestCorrelator.cxx
TestSubPixel_SOURCES = TestSubPixel.cxx

TESTS = TestStereoModel TestDisparity TestCorrelator
TESTS = TestStereoModel TestDisparity TestCorrelator TestSubPixel

#include $(top_srcdir)/config/instantiate.am

Expand Down
169 changes: 169 additions & 0 deletions src/vw/Stereo/tests/TestSubPixel.cxx
@@ -0,0 +1,169 @@
// __BEGIN_LICENSE__
// Copyright (C) 2006-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__


// TestCorrelator.h
#include <gtest/gtest.h>

#include <vw/Image/UtilityViews.h>
#include <vw/Stereo/CorrelatorView.h>
#include <vw/Stereo/SubpixelView.h>
#include <vw/Image/Transform.h>
#include <vw/Image.h> // write_image
#include <vw/FileIO.h>

#include <boost/random/linear_congruential.hpp>

using namespace vw;
using namespace vw::stereo;

namespace vw {
template<> struct PixelFormatID<Vector3> { static const PixelFormatEnum value = VW_PIXEL_GENERIC_3_CHANNEL; };
}

template <int istretch>
class SubPixelCorrelateTest : public ::testing::Test {
const int IMAGE_SIZE, HALF_IMAGE_SIZE;

public:
SubPixelCorrelateTest() : IMAGE_SIZE(100), HALF_IMAGE_SIZE(50) {}

protected:
typedef LogStereoPreprocessingFilter PreFilter;

void SetUp() {
stretch = float(istretch)/100;

boost::rand48 gen(10);
image1 = transform(channel_cast_rescale<uint8>(uniform_noise_view( gen, IMAGE_SIZE, IMAGE_SIZE )),
AffineTransform(Matrix2x2(3,0,0,3),Vector2()),
ZeroEdgeExtension(), BicubicInterpolation());
translation = HALF_IMAGE_SIZE-HALF_IMAGE_SIZE*stretch;
image2 = transform(image1, AffineTransform(Matrix2x2(stretch,0,0,1),
Vector2(translation,0) ),
ZeroEdgeExtension(), BicubicInterpolation());

starting_disp.set_size(IMAGE_SIZE,IMAGE_SIZE);
for ( int i = 0; i < IMAGE_SIZE ; i++ ) {
int disparity = stretch * i + translation - i;
for ( int j = 0; j < IMAGE_SIZE; j++ )
starting_disp(i,j) = disparity;
}
}

template <class ViewT>
double check_error( ImageViewBase<ViewT> const& input ) {
ViewT const& disparity = input.impl();
double error = 0;
for ( int i = 0; i < IMAGE_SIZE; i++ ) {
float expected = stretch * float(i) + translation - i;
for ( int j = 0; j < IMAGE_SIZE; j++ )
error += disparity(i,j)[1] + fabs(disparity(i,j)[0] - expected);
}
return error / (double(IMAGE_SIZE)*double(IMAGE_SIZE));
}

float stretch, translation;
ImageView<uint8> image1, image2;
ImageView<PixelMask<Vector2f> > starting_disp;
};

typedef SubPixelCorrelateTest<95> SubPixelCorrelate95Test;
typedef SubPixelCorrelateTest<90> SubPixelCorrelate90Test;
typedef SubPixelCorrelateTest<80> SubPixelCorrelate80Test;
typedef SubPixelCorrelateTest<70> SubPixelCorrelate70Test;

// Testing Parabola SubPixel
//--------------------------------------------------------------
TEST_F( SubPixelCorrelate95Test, Parabola95 ) {
typedef SubpixelView<PreFilter, ImageView<uint8> > SubView;
ImageView<PixelMask<Vector2f> > disparity_map =
SubView( starting_disp, image1, image2,
7, 7, true, true, 1,
PreFilter(1.4), false );
double error = check_error( disparity_map );
EXPECT_LT(error, 0.336);
}

TEST_F( SubPixelCorrelate90Test, Parabola90 ) {
typedef SubpixelView<PreFilter, ImageView<uint8> > SubView;
ImageView<PixelMask<Vector2f> > disparity_map =
SubView( starting_disp, image1, image2,
7, 7, true, true, 1,
PreFilter(1.4), false );
double error = check_error( disparity_map );
EXPECT_LT(error, 0.379);
}

TEST_F( SubPixelCorrelate80Test, Parabola80 ) {
typedef SubpixelView<PreFilter, ImageView<uint8> > SubView;
ImageView<PixelMask<Vector2f> > disparity_map =
SubView( starting_disp, image1, image2,
7, 7, true, true, 1,
PreFilter(1.4), false );
double error = check_error( disparity_map );
EXPECT_LT(error, 0.310);
}

TEST_F( SubPixelCorrelate70Test, Parabola70 ) {
typedef SubpixelView<PreFilter, ImageView<uint8> > SubView;
ImageView<PixelMask<Vector2f> > disparity_map =
SubView( starting_disp, image1, image2,
7, 7, true, true, 1,
PreFilter(1.4), false );
double error = check_error( disparity_map );
EXPECT_LT(error, 0.427);
}

// Testing Bayes EM SubPixel
//--------------------------------------------------------------
TEST_F( SubPixelCorrelate95Test, BayesEM95 ) {
typedef SubpixelView<PreFilter, ImageView<float> > SubView;
ImageView<PixelMask<Vector2f> > disparity_map =
SubView( starting_disp,
channel_cast_rescale<float>(image1),
channel_cast_rescale<float>(image2),
7, 7, true, true, 2,
PreFilter(1.4), false );
double error = check_error( disparity_map );
EXPECT_LT(error, 0.056);
}

TEST_F( SubPixelCorrelate90Test, BayesEM90 ) {
typedef SubpixelView<PreFilter, ImageView<float> > SubView;
ImageView<PixelMask<Vector2f> > disparity_map =
SubView( starting_disp,
channel_cast_rescale<float>(image1),
channel_cast_rescale<float>(image2),
7, 7, true, true, 2,
PreFilter(1.4), false );
double error = check_error( disparity_map );
EXPECT_LT(error, 0.127);
}

TEST_F( SubPixelCorrelate80Test, BayesEM80 ) {
typedef SubpixelView<PreFilter, ImageView<float> > SubView;
ImageView<PixelMask<Vector2f> > disparity_map =
SubView( starting_disp,
channel_cast_rescale<float>(image1),
channel_cast_rescale<float>(image2),
7, 7, true, true, 2,
PreFilter(1.4), false );
double error = check_error( disparity_map );
EXPECT_LT(error, 0.362);
}

TEST_F( SubPixelCorrelate70Test, BayesEM70 ) {
typedef SubpixelView<PreFilter, ImageView<float> > SubView;
ImageView<PixelMask<Vector2f> > disparity_map =
SubView( starting_disp,
channel_cast_rescale<float>(image1),
channel_cast_rescale<float>(image2),
7, 7, true, true, 2,
PreFilter(1.4), false );
double error = check_error( disparity_map );
EXPECT_LT(error, 0.748);
}

0 comments on commit 96fc037

Please sign in to comment.