Improved regions handling, added otsu algorithm