Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

So I recently read thisthis 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.

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.

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.

deleted 67 characters in body
Source Link

So I recently read thisthis excellent post about generating random points over arbitrary regions. I hope Wolfram eventually builds that functionality into Mathematica's RandomMathematica'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 anywhereanywhere within the coastlines/black regions.

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.

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.

Tweeted twitter.com/#!/StackMma/status/598886019799371776
Source Link
Histograms
  • 2.3k
  • 13
  • 21

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.