| 152 | return r; |
| 153 | } |
| 154 | VectorXf DenseCRF::pairwiseEnergy(const VectorXs & l, int term) { |
| 155 | assert( l.cols() == N_ ); |
| 156 | VectorXf r( N_ ); |
| 157 | r.fill(0.f); |
| 158 | |
| 159 | if( term == -1 ) { |
| 160 | for( unsigned int i=0; i<pairwise_.size(); i++ ) |
| 161 | r += pairwiseEnergy( l, i ); |
| 162 | return r; |
| 163 | } |
| 164 | |
| 165 | MatrixXf Q( M_, N_ ); |
| 166 | // Build the current belief [binary assignment] |
| 167 | for( int i=0; i<N_; i++ ) |
| 168 | for( int j=0; j<M_; j++ ) |
| 169 | Q(j,i) = (l[i] == j); |
| 170 | pairwise_[ term ]->apply( Q, Q ); |
| 171 | for( int i=0; i<N_; i++ ) |
| 172 | if ( 0 <= l[i] && l[i] < M_ ) |
| 173 | r[i] =-0.5*Q(l[i],i ); |
| 174 | else |
| 175 | r[i] = 0; |
| 176 | return r; |
| 177 | } |
| 178 | MatrixXf DenseCRF::startInference() const{ |
| 179 | MatrixXf Q( M_, N_ ); |
| 180 | Q.fill(0); |