Fix bugs in unary potentials calculation and MRF pairs construction