Merge pull request #2319 from Jiaolong/graph_cut

added graph cut and unit-test
fixed defects found by Coverity Scan