({{, (RefLink[LinearGradientImage, paclet:ref/LinearGradientImage])[gcol]
returns an image with values linearly changing from left to right based on gradient color gcol.}, {, (RefLink[LinearGradientImage, paclet:ref/LinearGradientImage])[{(Subscript[pos, 1]),(Subscript[pos, 2])}->gcol]
returns an image where the gradient starts at (Subscript[pos, 1]) and ends at (Subscript[pos, 2]).}, {, (RefLink[LinearGradientImage, paclet:ref/LinearGradientImage])[…,size]
returns a linear gradient image of the specified size.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[LinearGradientImage, paclet:ref/LinearGradientImage]) constructs a 2D or 3D image with constant gradient along a direction derived from the input specification.

Color scheme specification gcol can be any of the following:

The argument passed to the function f is by default the normalized distance between a pixel and the line going through (Subscript[pos, 1]), perpendicular to (Subscript[pos, 2])-(Subscript[pos, 1]).

Position specification (Subscript[pos, i]) can be any of the following:

Positions that are not constrained are taken to be centered.

By default, positions are assumed to be in the standard image coordinate system.

The size specification can be one of the following:

The default size is {150,150} for 2D images and {64,64,64} for 3D images.

(RefLink[LinearGradientImage, paclet:ref/LinearGradientImage])[] is equivalent to (RefLink[LinearGradientImage, paclet:ref/LinearGradientImage])[{(RefLink[Black, paclet:ref/Black]),(RefLink[White, paclet:ref/White])}].

(RefLink[LinearGradientImage, paclet:ref/LinearGradientImage]) accepts the following options:

Possible settings for (RefLink[DataRange, paclet:ref/DataRange]) include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (26)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Linear grayscale gradient from left to right:

LinearGradientImage[]

Linear blend of colors from left to right:

LinearGradientImage[{Blue,Yellow,Red}]

Linear gradient image along a given direction:

LinearGradientImage[{{Left,Bottom},{Right,Top}}->{Blue,Yellow,Red}]

OpenersExampleSection1(Spacer1)Scope  (14)

OpenersExampleSubsection0(Spacer1)Color Schemes  (5)

Linear blend of two colors:

LinearGradientImage[{Red,Yellow}]

Linear blend of multiple colors:

LinearGradientImage[{Red,Blue,Green,Yellow}]

Use a gradient color scheme:

LinearGradientImage["Rainbow"]

Use hue as the coloring function:

LinearGradientImage[Hue]

Specify a custom color function:

LinearGradientImage[RGBColor[#,1-#,#/2]&]

OpenersExampleSubsection1(Spacer1)Positions  (6)

By default, a linear gradient image from left to right is generated:

LinearGradientImage[ColorData["Rainbow"]]

A top-to-bottom gradient image:

LinearGradientImage[{Top,Bottom}->ColorData["Rainbow"]]

A diagonal gradient image:

LinearGradientImage[{{Left,Bottom},{Right,Top}}->ColorData["Rainbow"]]

If position along one dimension is not given, center alignment is used for that dimension:

LinearGradientImage[{Left,Top}->ColorData["Rainbow"]]

Left-to-right 3D gradient image:

LinearGradientImage[{Left,Right}->ColorData["Rainbow"],{7,7,7}]

Diagonal 3D gradient image:

LinearGradientImage[{{Left,Front,Top},{Right,Back,Bottom}}->ColorData["Rainbow"],{8,5,3}]

OpenersExampleSubsection2(Spacer1)Size  (3)

By default, a 2D image of size {150,150} is generated:

LinearGradientImage[Hue]

Specify the output size:

LinearGradientImage[Hue,{50,50}]

If absolute pixel positions are given, the minimum image dimensions containing the positions are returned:

LinearGradientImage[{{0,0},{100,100}}->Hue]

Specify a different output size:

LinearGradientImage[{{0,0},{100,100}}->Hue,{150,150}]

By default, a 3D image of size {64,64,64} is generated:

LinearGradientImage[{{Left,Front,Bottom},{Right,Back,Top}}->"Rainbow"]

Specify the output size:

LinearGradientImage[{{Left,Front,Bottom},{Right,Back,Top}}->ColorData["Rainbow"],{40,30,20}]

OpenersExampleSection2(Spacer1)Options  (8)

OpenersExampleSubsection3(Spacer1)ColorFunction  (3)

With no color specification, (RefLink[GrayLevel, paclet:ref/GrayLevel]) is the default color function:

LinearGradientImage[{{0,0},{100,100}},{100,100}]

Specify a different color function:

LinearGradientImage[{{0,0},{100,100}},{100,100},ColorFunction->Hue]

Use a built-in color gradient:

LinearGradientImage[{{0,0},{100,100}},{100,100},ColorFunction->ColorData["Rainbow"]]

Use (RefLink[Blend, paclet:ref/Blend]) to specify a color function that is a blend of multiple colors:

LinearGradientImage[{{0,0},{100,100}},{100,100},ColorFunction->(Blend[{Blue,Yellow,Green},#]&)]

When grayscale 3D images are produced, (RefLink[ColorFunction, paclet:ref/ColorFunction])->"GrayLevelOpacity" is used in (RefLink[Image3D, paclet:ref/Image3D]):

LinearGradientImage[{Left,Right},{10,10,10}]

With both (RefLink[ColorFunction, paclet:ref/ColorFunction]) and end point colors specified, color function is ignored:

LinearGradientImage[{Left->Green,Right->Red},ColorFunction->GrayLevel]

OpenersExampleSubsection4(Spacer1)ColorFunctionScaling  (2)

By default, the color function parameters are rescaled between 0 and 1:

LinearGradientImage[(Blend[{{0,Red},{1,Yellow}},#]&),{200,20}]

Scaled values might not be suitable for some color functions:

Image[LinearGradientImage[ColorData[2],{20,5}],ImageSize->100]

Use (RefLink[ColorFunctionScaling, paclet:ref/ColorFunctionScaling])->(RefLink[False, paclet:ref/False]):

Image[LinearGradientImage[ColorData[2],{20,5},ColorFunctionScaling->False],ImageSize->100]

OpenersExampleSubsection5(Spacer1)DataRange  (2)

The default (RefLink[DataRange, paclet:ref/DataRange]) is the size of the image:

LinearGradientImage[{{0,0},{50,50}}->Hue,{100,100}]

Specify a different data range:

LinearGradientImage[{{0,0},{50,50}}->Hue,{100,100},DataRange->{{0,50},{0,50}}]

Use a normalized data range to get the same effect, regardless of the image dimensions:

LinearGradientImage[{{1/2,1/2},{1,1}}->Hue,{50,50},DataRange->{{0,1},{0,1}}]

LinearGradientImage[{{1/2,1/2},{1,1}}->Hue,{100,50},DataRange->{{0,1},{0,1}}]

OpenersExampleSubsection6(Spacer1)Padding  (1)

By default, "Fixed" padding is used:

LinearGradientImage[{{20,20},{80,80}},{100,100}]

Use a constant padding value:

LinearGradientImage[{{20,20},{80,80}},{100,100},Padding->Red]

Specify a padding scheme:

LinearGradientImage[{{20,20},{80,80}},{100,100},Padding->"Periodic"]

OpenersExampleSection3(Spacer1)Applications  (1)

Apply different gradient effects to an image:

img=;
{g1,g2}=LinearGradientImage[{Bottom,{Center,1/3}}->#,ImageDimensions[img],DataRange->{0,1}]&/@{"SandyTerrain","GreenBrownTerrain"}

Blend[{img,#}]&/@{g1,g2}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[RadialGradientImage, paclet:ref/RadialGradientImage])  ▪  (RefLink[Blend, paclet:ref/Blend])  ▪  (RefLink[ConstantImage, paclet:ref/ConstantImage])  ▪  (RefLink[RandomImage, paclet:ref/RandomImage])  ▪  (RefLink[Image, paclet:ref/Image])  ▪  (RefLink[ColorData, paclet:ref/ColorData])  ▪  (RefLink[GradientFilter, paclet:ref/GradientFilter])}})}})

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