Commit e5752c34 authored by Davis King's avatar Davis King

Slightly changed make_potts_grid_problem() so that it allows the user to give

two images with different pixel types rather than requiring the images to have
the same pixel types.
parent 8fb7aa5c
...@@ -819,20 +819,22 @@ namespace dlib ...@@ -819,20 +819,22 @@ namespace dlib
namespace impl namespace impl
{ {
template < template <
typename image_type, typename pixel_type1,
typename pixel_type2,
typename model_type typename model_type
> >
struct potts_grid_image_pair_model struct potts_grid_image_pair_model
{ {
const typename image_type::type* data1; const pixel_type1* data1;
const typename image_type::type* data2; const pixel_type2* data2;
const model_type& model; const model_type& model;
const long nr_; const long nr_;
const long nc_; const long nc_;
template <typename image_type1, typename image_type2>
potts_grid_image_pair_model( potts_grid_image_pair_model(
const model_type& model_, const model_type& model_,
const image_type& img1, const image_type1& img1,
const image_type& img2 const image_type2& img2
) : ) :
model(model_), model(model_),
nr_(img1.nr()), nr_(img1.nr()),
...@@ -913,13 +915,14 @@ namespace dlib ...@@ -913,13 +915,14 @@ namespace dlib
template < template <
typename pair_image_model, typename pair_image_model,
typename pixel_type, typename pixel_type1,
typename pixel_type2,
typename mem_manager typename mem_manager
> >
impl::potts_grid_image_pair_model<array2d<pixel_type,mem_manager>, pair_image_model> make_potts_grid_problem ( impl::potts_grid_image_pair_model<pixel_type1, pixel_type2, pair_image_model> make_potts_grid_problem (
const pair_image_model& model, const pair_image_model& model,
const array2d<pixel_type,mem_manager>& img1, const array2d<pixel_type1,mem_manager>& img1,
const array2d<pixel_type,mem_manager>& img2 const array2d<pixel_type2,mem_manager>& img2
) )
{ {
DLIB_ASSERT(get_rect(img1) == get_rect(img2), DLIB_ASSERT(get_rect(img1) == get_rect(img2),
...@@ -928,7 +931,7 @@ namespace dlib ...@@ -928,7 +931,7 @@ namespace dlib
<< "\n\t get_rect(img1): " << get_rect(img1) << "\n\t get_rect(img1): " << get_rect(img1)
<< "\n\t get_rect(img2): " << get_rect(img2) << "\n\t get_rect(img2): " << get_rect(img2)
); );
typedef impl::potts_grid_image_pair_model<array2d<pixel_type,mem_manager>, pair_image_model> potts_type; typedef impl::potts_grid_image_pair_model<pixel_type1, pixel_type2, pair_image_model> potts_type;
return potts_type(model,img1,img2); return potts_type(model,img1,img2);
} }
......
...@@ -530,10 +530,10 @@ namespace dlib ...@@ -530,10 +530,10 @@ namespace dlib
// must also be capable of representing signed values. // must also be capable of representing signed values.
typedef an_integer_or_real_type value_type; typedef an_integer_or_real_type value_type;
template <typename pixel_type> template <typename pixel_type1, typename pixel_type2>
value_type factor_value ( value_type factor_value (
const pixel_type& v1, const pixel_type1& v1,
const pixel_type& v2 const pixel_type2& v2
) const; ) const;
/*! /*!
requires requires
...@@ -601,13 +601,14 @@ namespace dlib ...@@ -601,13 +601,14 @@ namespace dlib
template < template <
typename pair_image_model, typename pair_image_model,
typename pixel_type, typename pixel_type1,
typename pixel_type2,
typename mem_manager typename mem_manager
> >
potts_grid_problem make_potts_grid_problem ( potts_grid_problem make_potts_grid_problem (
const pair_image_model& model, const pair_image_model& model,
const array2d<pixel_type,mem_manager>& img1, const array2d<pixel_type1,mem_manager>& img1,
const array2d<pixel_type,mem_manager>& img2 const array2d<pixel_type2,mem_manager>& img2
); );
/*! /*!
requires requires
......
...@@ -1068,6 +1068,70 @@ namespace ...@@ -1068,6 +1068,70 @@ namespace
DLIB_TEST(labels[3] != 0); DLIB_TEST(labels[3] != 0);
} }
struct potts_pair_image_model
{
typedef double value_type;
template <typename pixel_type1, typename pixel_type2>
value_type factor_value (
const pixel_type1& ,
const pixel_type2& v2
) const
{
return v2;
}
template <typename pixel_type>
value_type factor_value_disagreement (
const pixel_type& v1,
const pixel_type& v2
) const
{
if (v1 == v2)
return 10;
else
return 0;
}
};
void test_potts_pair_grid()
{
array2d<int> img1(40,40);
array2d<double> img2(40,40);
assign_all_pixels(img1, -1);
assign_all_pixels(img2, -1);
img1[4][4] = 1000;
img2[4][3] = 1;
img2[4][4] = 1;
img2[4][5] = 1;
img2[3][3] = 1;
img2[3][4] = 1;
img2[3][5] = 1;
img2[5][3] = 1;
img2[5][4] = 1;
img2[5][5] = 1;
array2d<unsigned char> labels;
find_max_factor_graph_potts(make_potts_grid_problem(potts_pair_image_model(),img2,img1), labels);
dlog << LINFO << "num true labels: " << sum(matrix_cast<int>(mat(labels)!=0));
DLIB_TEST(sum(matrix_cast<int>(mat(labels)!=0)) == 9);
DLIB_TEST(sum(matrix_cast<int>(mat(labels)==0)) == (int)img1.size()-9);
DLIB_TEST(labels[4][3]);
DLIB_TEST(labels[4][4]);
DLIB_TEST(labels[4][5]);
DLIB_TEST(labels[3][3]);
DLIB_TEST(labels[3][4]);
DLIB_TEST(labels[3][5]);
DLIB_TEST(labels[5][3]);
DLIB_TEST(labels[5][4]);
DLIB_TEST(labels[5][5]);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -1087,6 +1151,7 @@ namespace ...@@ -1087,6 +1151,7 @@ namespace
void perform_test ( void perform_test (
) )
{ {
test_potts_pair_grid();
test_inf(); test_inf();
for (int i = 0; i < 500; ++i) for (int i = 0; i < 500; ++i)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment