Pixel { public static double distance(RealMatrix x, RealMatrix y){ double res = 0; for(int i=0;i<x.getRowDimension();i++){ for(int j=0;j<x.getColumnDimension();j++){ res += Math.abs(x.getEntry(i, j) - y.getEntry(i, j))*(DBW(x,i,j,1) + DBW(y,i,j,1)); } } return res; }  static int DBW(RealMatrix m, int i, int j, int fringe); static double distance(RealMatrix x, RealMatrix y);  }
@Test public void test1(){ double[][] m1 = {{1,0,1},{0,1,1},{1,1,1}}; double[][] m2 = {{0,1,1},{0,0,1},{1,0,1}}; Asserts.assertEqualLength(m1, m2); Asserts.assertIsBinary(m1); Asserts.assertIsBinary(m2); RealMatrix rm1 = new Array2DRowRealMatrix(m1); RealMatrix rm2 = new Array2DRowRealMatrix(m2); double res = Pixel.distance(rm1, rm2); Asserts.assertEquals(res, 8); }
@Test public void test2(){ double[][] m1 = {{1,0,1,0,1},{0,0,0,1,1},{1,0,1,1,1},{1,1,1,1,1},{0,1,1,0,1}}; double[][] m2 = {{1,1,1,1,0},{1,1,0,1,0},{1,1,1,0,1},{0,0,1,0,1},{1,0,1,1,1}}; Asserts.assertEqualLength(m1, m2); Asserts.assertIsBinary(m1); Asserts.assertIsBinary(m2); RealMatrix rm1 = new Array2DRowRealMatrix(m1); RealMatrix rm2 = new Array2DRowRealMatrix(m2); double res = Pixel.distance(rm1, rm2); Asserts.assertEquals(res, 29); }
@Test public void test3(){ double[][] m1 = {{1,0,1,0,1,1,1,0},{1,1,1,0,0,0,1,1},{1,0,0,1,0,1,1,1},{1,0,1,1,1,1,1,1},{1,0,1,0,1,1,0,1}}; double[][] m2 = {{1,1,1,1,0,0,0,1},{1,0,0,1,1,0,1,0},{0,1,1,1,1,1,0,1},{1,1,1,0,0,1,0,1},{1,0,1,0,1,1,1,1}}; Asserts.assertEqualLength(m1, m2); Asserts.assertIsBinary(m1); Asserts.assertIsBinary(m2); RealMatrix rm1 = new Array2DRowRealMatrix(m1); RealMatrix rm2 = new Array2DRowRealMatrix(m2); double res = Pixel.distance(rm1, rm2); Asserts.assertEquals(res, 42); }