public static double [ ] [ ] computeWeightMatrix ( final int quanth , final int quants , final int quantb ) { final int dim = quanth * quants * quantb ; final DoubleWrapper tmp = new DoubleWrapper ( ) ; // To return cosine assert ( dim > 0 ) ; final double [ ] [ ] m = new double [ dim ] [ dim ] ; for ( int x = 0 ; x < dim ; x ++ ) { final int hx = x / ( quantb * quants ) ; final int sx = ( x / quantb ) % quants ; final int bx = x % quantb ; for ( int y = x ; y < dim ; y ++ ) { final int hy = y / ( quantb * quants ) ; final int sy = ( y / quantb ) % quants ; final int by = y % quantb ; final double shx = FastMath . sinAndCos ( ( hx + .5 ) / quanth * MathUtil . TWOPI , tmp ) ; final double chx = tmp . value ; final double shy = FastMath . sinAndCos ( ( hy + .5 ) / quanth * MathUtil . TWOPI , tmp ) ; final double chy = tmp . value ; final double cos = chx * ( sx + .5 ) / quants - chy * ( sy + .5 ) / quants ; final double sin = shx * ( sx + .5 ) / quants - shy * ( sy + .5 ) / quants ; final double db = ( bx - by ) / ( double ) quantb ; final double val = 1. - FastMath . sqrt ( ( db * db + sin * sin + cos * cos ) / 5 ) ; m [ x ] [ y ] = m [ y ] [ x ] = val ; } } return m ; }
Compute the weight matrix for HSB similarity .