Re: Invert Black/White Colors of Binary Images
- To: mathgroup at smc.vnet.net
- Subject: [mg84173] Re: Invert Black/White Colors of Binary Images
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 12 Dec 2007 19:56:56 -0500 (EST)
- Organization: Uni Leipzig
- References: <fjnupg$fhc$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi, RandomBinaryImage[white_?NumericQ, nx_Integer, ny_Integer] := Module[{dta}, dta = Table[If[Random[] < white, 1, 0], {nx*ny}]; Graphics[ Raster[Partition[dta, nx], {{0, 0}, {nx, ny}}, {0, 1}, ColorFunction -> GrayLevel] ] ] should create a random binary image of size nx*ny with 0<=white<=1 white pixels. So RandomBinaryImage[0.05, 256, 256] will generate approx 5% white pixels and RandomBinaryImage[0.95, 256, 256] 95 % white pixels. Regards Jens Tara.Ann.Lorenz at gmail.com wrote: > Hi, > > I am using the following code to create black and white images with > 5% black pixels and 95% white pixels: > > blackcolor = Table[1, {45}]; > whitecolor = Table[0, {855}]; > arrayvalues = Join[blackcolor, whitecolor]; > randompermutation := RandomSample[Range[1, 900]]; > image := Partition[arrayvalues[[randompermutation]], 30]; > t1 = Graphics[Raster[image]] > > How can I invert the coloring to have 5% white and 95% black?? > > Thank you, > Tara >