uses mask instead of thresholding