1 // This is brl/bseg/brip/tests/test_homography.cxx
2 #define DEBUG
3 #include "vil1/vil1_memory_image_of.h"
4 #ifdef DEBUG
5 #include "vil1/vil1_save.h"
6 #endif
7 #include <brip/brip_vil1_float_ops.h>
8 #include "testlib/testlib_test.h"
9 #include "vnl/vnl_matrix_fixed.h"
10 #include "vnl/vnl_vector_fixed.h"
11 #include <vgl/algo/vgl_h_matrix_2d.h>
12 #include <vnl/algo/vnl_svd.h>
test_homography()13 static void test_homography()
14 {
15 const int w = 100, h = 100;
16 vil1_memory_image_of<float> input(w,h), out;
17 // diagonal periodic stripes
18 int period = 5;
19 for (int y = 0; y< h; y++)
20 for (int x = 0; x<w; x++)
21 input(x,y)=50;
22
23 for (int p = 0; p<h; p+=period)
24 for (int y = 0; y< h; y++)
25 for (int x = 0; x<w; x++)
26 if (x==y+p)
27 input(x,y)=150;
28 //first try simple rotation
29 vnl_matrix_fixed<double,3, 3> M;
30 M[0][0]= 0.6; M[0][1]= -0.8; M[0][2]= 70.7;
31 M[1][0]= 0.8; M[1][1]= 0.6; M[1][2]= 0;
32 M[2][0]= 0; M[2][1]= 0; M[2][2]= 1;
33 vgl_h_matrix_2d<double> H(M);
34 std::cout << "H\n" << H << std::endl;
35 if (!brip_vil1_float_ops::homography(input, H, out))
36 {
37 std::cout << "homography failed\n";
38 return;
39 }
40
41 vil1_memory_image_of<unsigned char> char_in = brip_vil1_float_ops::convert_to_byte(input);
42 vil1_memory_image_of<unsigned char> char_out = brip_vil1_float_ops::convert_to_byte(out, 0, 255);
43 #ifdef DEBUG
44 vil1_save(char_in, "./homg_input.tif");
45 vil1_save(char_out, "./homg_out.tif");
46 #endif
47 #if 0
48 vnl_matrix_fixed<double,4, 3> A;
49 A[0][0]= 1.0 ; A[0][1]= 0.0 ; A[0][2]= 2.0 ;
50 A[1][0]= 1.0; A[1][1]= 1.0; A[1][2]= 0.0;
51 A[2][0]= 2.0; A[2][1]= 0; A[2][2]= 4.1;
52 A[3][0]= 2; A[3][1]= 2.1 ; A[3][2]= 0.0;
53 vnl_svd<double> SVD(A);
54 vnl_matrix_fixed<double, 4,3> U = SVD.U();
55 std::cout << "U\n" << U << '\n';
56
57 vnl_matrix_fixed<double, 3,3> W = SVD.W();
58 std::cout << "Sigma\n" << W << '\n';
59
60 vnl_matrix_fixed<double, 3,3> V = SVD.V();
61 std::cout << "V\n" << V << '\n';
62 vnl_vector_fixed<double, 3> nv = SVD.nullvector() ;
63 std::cout << "Nullvector " << nv << '\n'
64 << "nullresidue " << A*nv << '\n';
65 #endif
66 }
67
68
69 TESTMAIN(test_homography);
70