| 247 | return r; |
| 248 | } |
| 249 | VectorXf DenseCRF::pairwiseEnergy(const VectorXs & l, int term) { |
| 250 | assert( l.cols() == N_ ); |
| 251 | VectorXf r( N_ ); |
| 252 | r.fill(0.f); |
| 253 | |
| 254 | if( term == -1 ) { |
| 255 | for( unsigned int i=0; i<pairwise_.size(); i++ ) |
| 256 | r += pairwiseEnergy( l, i ); |
| 257 | return r; |
| 258 | } |
| 259 | |
| 260 | MatrixXf Q( M_, N_ ); |
| 261 | // Build the current belief [binary assignment] |
| 262 | for( int i=0; i<N_; i++ ) |
| 263 | for( int j=0; j<M_; j++ ) |
| 264 | Q(j,i) = (l[i] == j); |
| 265 | pairwise_[ term ]->apply( Q, Q ); |
| 266 | for( int i=0; i<N_; i++ ) |
| 267 | if ( 0 <= l[i] && l[i] < M_ ) |
| 268 | r[i] =-0.5*Q(l[i],i ); |
| 269 | else |
| 270 | r[i] = 0; |
| 271 | return r; |
| 272 | } |
| 273 | MatrixXf DenseCRF::startInference() const{ |
| 274 | MatrixXf Q( M_, N_ ); |
| 275 | Q.fill(0); |