Matlab code ready to run. It is intentionally kept very simple so it can provide a starting point for new projects. Source code for knn matting cvpr 2012 tpami 2013.