I have an image and I am applying a mask on the image. I want to choose radomly points that belong to this mask. Is there a way of doing this?

For example

from scipy import misc

import numpy as np
image = misc.face()[:,:,2]

mask = image> image.max()*0.9
image = image*mask
from skimage.morphology import local_maxima
lm = local_maxima(image)

How do I get a random configuration of 10 points from lm ? I have found this workaround

x,y = local_maxima(lm,indices=True)
coords = [(x[np.random.randint(low=0, high=len(x))],y[np.random.randint(low=0, high=len(x))]) for _ in range(10)]

Is there a better way of doing this?

0 Answers