Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Create random binary images
Replies: 8   Last Post: Mar 5, 2012 2:04 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jens-Peer Kuska

Posts: 3,237
Registered: 12/7/04
Re: Create random binary images
Posted: Nov 28, 2007 5:53 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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!
>




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.