(lookup_image): Build mask before applying an algorithm.