Efficient inference and learning for computer vision labelling problems