Add a function to apply a mask to an image.