|
|
Re: Create random binary images
Posted:
Nov 28, 2007 5:53 AM
|
|
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
Anonymous 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! >
|
|