Factored binarization code and used numpy set functions.