Simple binarization based on threshold function
Should be optimized in next few commits