({{, (RefLink[RandomImage, paclet:ref/RandomImage])[max]
gives an image with pseudorandom pixel values in the range 0 to max.}, {, (RefLink[RandomImage, paclet:ref/RandomImage])[{min,max}]
generates pseudorandom pixel values in the range min to max.}, {, (RefLink[RandomImage, paclet:ref/RandomImage])[dist]
generates pixel values using a symbolic distribution dist.}, {, (RefLink[RandomImage, paclet:ref/RandomImage])[…,size]
generates a random image of the specified size.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[RandomImage, paclet:ref/RandomImage]) gives an image where pixel values are drawn from a specified distribution. The pixel values are not correlated spatially.

Random images can be used for creating synthetic noise images and image effects.

(RefLink[RandomImage, paclet:ref/RandomImage]) by default gives an image of a real type.

(RefLink[RandomImage, paclet:ref/RandomImage])[] is equivalent to (RefLink[RandomImage, paclet:ref/RandomImage])[1,{150,150}].

(RefLink[RandomImage, paclet:ref/RandomImage])[…] is equivalent to (RefLink[RandomImage, paclet:ref/RandomImage])[…,{150,150}].

The size specification can be one of the following:

The following options are supported:

OpenersPrimaryExamplesSection(Spacer1)Examples  (28)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Generate a random image:

RandomImage[1,{100,100}]

Generate a random RGB image:

RandomImage[1,{100,100},ColorSpace->"RGB"]

Generate a random 3D image:

RandomImage[1,{50,40,20}]

OpenersExampleSection1(Spacer1)Scope  (7)

OpenersExampleSubsection0(Spacer1)Distribution  (5)

By default, pixel values range from 0 to 1:

RandomImage[]

Specify a range of pixel values:

RandomImage[{.5,.8}]

Generate an image from pseudorandom values in the range 0 to max=0.3`:

RandomImage[.3]

A random image from a distribution:

RandomImage[NormalDistribution[.5,.1]]

Generate a 4-channel image using some multivariate distribution:

RandomImage[MultinormalDistribution[{0,.1,.2,.3},.02*{{1,.2,0,0},{.2,1,.3,0},{0,.3,1,0},{0,0,0,1}}]]

OpenersExampleSubsection1(Spacer1)Size  (2)

By default, a 150 ×150 2D image is generated:

RandomImage[1]

Specify the image dimensions for a square image:

RandomImage[1,100]

Specify the image dimensions:

RandomImage[1,{200,100}]

Specify the 3D image dimensions:

RandomImage[1,{40,30,20}]

OpenersExampleSection2(Spacer1)Options  (5)

OpenersExampleSubsection3(Spacer1)ColorSpace  (4)

By default, no explicit color space is assumed:

RandomImage[1]

ImageColorSpace[%]

Generate a "Grayscale" image:

RandomImage[1,ColorSpace->"Grayscale"]

ImageColorSpace[%]

Generate a random "RGB" image:

RandomImage[1,ColorSpace->"RGB"]

Generate an "HSB" image using some univariate distribution:

RandomImage[UniformDistribution[{.2,.6}],ColorSpace->"HSB"]

Generate a "LAB" image using a multivariate uniform distribution with specific bounds:

RandomImage[UniformDistribution[{{0,1},{-1,1},{-1,1}}],ColorSpace->"LAB"]

OpenersExampleSubsection4(Spacer1)ImageSize  (1)

By default, the image is created with (RefLink[ImageSize, paclet:ref/ImageSize])->(RefLink[Automatic, paclet:ref/Automatic]):

RandomImage[1,{50,50}]

Specify the display size:

RandomImage[1,{50,50},ImageSize->100]

OpenersExampleSection3(Spacer1)Applications  (4)

Additive noise:

i=;
ImageAdd[i,RandomImage[{-.1,.1},ImageDimensions[i]]]

Multiplicative noise:

i=;
ImageMultiply[i,RandomImage[{0.8,1.2},ImageDimensions[i]]]

Image of Laplacian noise:

RandomImage[LaplaceDistribution[0,.2],{100,100}]

RGB image simulating salt-and-pepper noise using a heavy-tail distribution:

RandomImage[CauchyDistribution[0,.2],{100,100},ColorSpace->"RGB"]

OpenersExampleSection4(Spacer1)Properties & Relations  (7)

Generate an image with constant intensity:

RandomImage[EmpiricalDistribution[{.7}],{100,100}]

Use the specialized function (RefLink[ConstantImage, paclet:ref/ConstantImage]) instead:

ConstantImage[.7,{100,100}]

Generate the random data using (RefLink[RandomReal, paclet:ref/RandomReal]):

Image[RandomReal[1,{100,100}]]

Generate a random binary image using (RefLink[RandomInteger, paclet:ref/RandomInteger]):

Image[RandomInteger[1,{100,100}]]

Generate the random data using (RefLink[RandomVariate, paclet:ref/RandomVariate]):

Image[RandomVariate[NormalDistribution[.5,.1],{100,100}]]

In a uniformly random image, neighboring pixels are not correlated:

image=RandomImage[1]

ImageHistogram[image]

ImageCooccurrence[image,32]//MatrixPlot

After local filtering, pixel values drawn from the original distribution are spatially correlated:

imgcorr=HistogramTransform[GaussianFilter[image,3],image]

ImageCooccurrence[imgcorr,32]//MatrixPlot

Create an image with pixels randomly chosen from a list of colors:

Image[RandomChoice[{Red,Green,Blue},{10,10}]]

Create an image from colors randomly chosen from a convex hull defined by a list of colors:

Image[RandomPoint[ConvexHullMesh[List@@@{Red,Green,Blue}],{10,10}]]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

Out-of-range pixel values are rendered as black or white:

RandomImage[{-10,10},{100,100}]

Use (RefLink[ImageAdjust, paclet:ref/ImageAdjust]) to see the full range of values:

ImageAdjust[%]

OpenersExampleSection6(Spacer1)Neat Examples  (1)

Show the effect of various types of noise: original image, Poisson noise, uniform noise, Gaussian noise, Laplacian noise, salt-and-pepper noise:

img= ;
dims=ImageDimensions@img;
l=Flatten@ImagePartition[img,{First@dims/6,Last@dims}];
ImageAssemble[ImagePad[#,{{1,1},{0,0}}]&/@Flatten[{First@l,ImageEffect[l[[2]],{"PoissonNoise",.5}],MapThread[ImageAdd[#1,RandomImage[#2,ImageDimensions@#1]]&,{l[[3;;]],{UniformDistribution[{-.2,.2}],NormalDistribution[0,.1],LaplaceDistribution[0,.05],CauchyDistribution[0,.02]}}]}]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[RandomVariate, paclet:ref/RandomVariate])  ▪  (RefLink[ImageEffect, paclet:ref/ImageEffect])  ▪  (RefLink[RandomReal, paclet:ref/RandomReal])  ▪  (RefLink[RandomColor, paclet:ref/RandomColor])  ▪  (RefLink[ConstantImage, paclet:ref/ConstantImage])  ▪  (RefLink[Image, paclet:ref/Image])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Creating & Importing Images, paclet:guide/CreatingAndImportingImages])}, {▪(RefLinkPlain[Random Number Generation, paclet:guide/RandomNumberGeneration])}})}})