MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Create random binary images

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83692] Re: Create random binary images
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 28 Nov 2007 05:38:55 -0500 (EST)
  • References: <figtob$f90$1@smc.vnet.net>

Hi,

BinaryMatrix[prob_, n_Integer, m_Integer] :=
  Table[If[Random[] < prob, 1, 0], {m}, {n}]


RandomImage[prob_, n_Integer, m_Integer] :=
  Graphics[
   Raster[BinaryMatrix[prob, n, m], {{0, 0}, {n, m}}, {0, 1},
    ColorFunction -> GrayLevel], AspectRatio -> Automatic,
   ImageSize -> {n, m}, PlotRangePadding -> None]

and

RandomImage[0.05,30,30]

will do what you want.

Regards
   Jens

Tara.Ann.Lorenz at gmail.com wrote:
> Hello,
> 
> I am trying to create several random binary images of 30x30.  I want
> the outputs to be 1's and 0's, with 5% of the outputs being 1's.  Any
> ideas on how to code this in Mathematica?
> 
> Thanks!
> Tara
> 


  • Prev by Date: Re: ListContourPlot on a torus
  • Next by Date: Re: is the visibility of a Polygon[] exposed?
  • Previous by thread: Re: Create random binary images
  • Next by thread: Re: Create random binary images