Updated with threshold operation in image preprocessing