| 19 | } |
| 20 | |
| 21 | VectorXs dense_crf_inference(const unsigned char * img, const float * prob, int H, int W, int C, CRFParam param) |
| 22 | { |
| 23 | MatrixXf unary = computeUnary(prob, H, W, C); |
| 24 | |
| 25 | // Setup the CRF model |
| 26 | DenseCRF2D crf(W, H, C); |
| 27 | // Specify the unary potential as an array of size W*H*(#classes) |
| 28 | // packing order: x0y0l0 x0y0l1 x0y0l2 .. x1y0l0 x1y0l1 ... |
| 29 | crf.setUnaryEnergy( unary ); |
| 30 | |
| 31 | // add a color dependent term (feature = xyrgb) |
| 32 | // x_stddev = 60 |
| 33 | // y_stddev = 60 |
| 34 | // r_stddev = g_stddev = b_stddev = 20 |
| 35 | // weight = 10 |
| 36 | crf.addPairwiseBilateral(param.alpha, param.alpha, param.beta, param.beta, param.beta, img, new PottsCompatibility( param.w1 ) ); |
| 37 | |
| 38 | // add a color independent term (feature = pixel location 0..W-1, 0..H-1) |
| 39 | // x_stddev = 3 |
| 40 | // y_stddev = 3 |
| 41 | // weight = 3 |
| 42 | crf.addPairwiseGaussian( param.gamma, param.gamma, new PottsCompatibility( param.w2 ) ); |
| 43 | |
| 44 | // Do map inference |
| 45 | // MatrixXf Q = crf.startInference(), t1, t2; |
| 46 | // printf("kl = %f\n", crf.klDivergence(Q) ); |
| 47 | // for( int it=0; it<5; it++ ) { |
| 48 | // crf.stepInference( Q, t1, t2 ); |
| 49 | // printf("kl = %f\n", crf.klDivergence(Q) ); |
| 50 | // } |
| 51 | // VectorXs map = crf.currentMap(Q); |
| 52 | VectorXs map = crf.map(param.iter); |
| 53 | return map; |
| 54 | } |
no test coverage detected