Skip to main content
2 of 3
deleted 67 characters in body

Generating uniform random points over a binary image

So I recently read this excellent post about generating random points over arbitrary regions. I hope Wolfram eventually builds that functionality into Mathematica's Random functions. I want to do this for binary images.

Given a binary image like this:

Map of the UK

... I can generate random lattice points over the black parts by doing:

 ListPlot[RandomSample[PixelValuePositions[Binarize[img], Black],1500],
  AspectRatio -> ImageAspectRatio[img]]

which gives this plot:

Random lattice points

However, the problem is that all generated random points will lie on integer coordinates. For example, the point {150, 100} can be generated by my approach, yet the point {150.278, 100.123} will never be generated. I want to generate random points uniformly anywhere within the coastlines/black regions.

Histograms
  • 2.3k
  • 13
  • 21