graph cuts implementation in javascript