File Exchange

image thumbnail

Draw Color Gradients

version 1.1.1.0 (64 KB) by DGM
Create two-point or multipoint gradients with configurable symmetry and interpolation method.

4 Downloads

Updated 24 Apr 2019

View License

LINGRAD() and RADGRAD() fill most basic multipoint gradient generation needs. For linear gradients, all that is needed for common 2-point gradients are the endpoints of the gradient (in normalized coordinates), and the endpoint colors. Radial gradients are specified with a center point and radius.
.
For nonuniform or asymmetric multipoint gradients, the individual breakpoints can be specified. Multiple interpolation curves help reduce the need for multipoint gradients. All blending is simple RGB. The thumbnail image illustrates the various two-point interpolation curves. Included are a handful of example demonstrations including nonuniform multipoint gradients.
.
Examples from the MIMT manual:
http://myplace.frontier.com/~chooks9592/manual/html/lingrad.html
http://myplace.frontier.com/~chooks9592/manual/html/radgrad.html
.
LINGRAD(SIZE, POINTS, COLORS, {METHOD}, {BREAKPOINTS}, {OUTCLASS})
____returns an image of specified size containing
____the multipoint linear gradient specified.
____gradient type is linear interpolated rgb
SIZE is a vector specifying output image size
POINTS is a 2x2 matrix specifying gradient endpoints
____[y0 x0; y1 x1] (normalized coordinates)
COLORS is an array specifying the colors at the endpoints
____e.g. [0; 255] or [255 0 0; 0 0 255] depending on SIZE(3)
____The white value depends on OUTCLASS
____ 255 for 'uint8', 65535 for 'uint16', 1 for float classes
METHOD specified how colors are interpolated between points
____this helps avoid the need for multipoint gradients
____the first six methods are listed in order of decreasing endslope
____'invert' is the approximate inverse of the cosine function
____'softinvert' is the approximate inverse of the softease function
____'linear' for linear interpolation (default)
____'softease' is a blend between linear and cosine
____'cosine' for cosine interpolation
____'ease' is a polynomial ease curve
____'waves' is linear interpolation with a superimposed sinusoid
____ when specified, an additional parameter vector
____ [amplitude numcycles] may also be specified (default [0.05 10]).
____ 'waves' method only available for two-point gradients
BREAKPOINTS optionally specify the location of the breakpoints
____in a gradient with more than two colors. By default,
____all breakpoints are distributed evenly from 0 to 1.
____If specified, numel(breakpoints) must be the same as the number
____of colors specified. First and last breakpoints are always 0 and 1.
____ex: [0 0.18 0.77 1]
OUTCLASS specifies the output image class (default 'uint8')
____Supports 'uint8', 'uint16', 'single', and 'double'
.
These functions are part of my image manipulation toolbox:
http://www.mathworks.com/matlabcentral/fileexchange/53786-image-manipulation-toolbox

Cite As

DGM (2019). Draw Color Gradients (https://www.mathworks.com/matlabcentral/fileexchange/53356-draw-color-gradients), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

craq

Just trying this out quickly, gradientexamples.m causes multiple errors immediately:
Undefined function or variable 't'.
Undefined function or variable 'coint'.
Undefined function 'imrange' for input arguments of type 'double'.

The last one is a dependency on another of your fileexchange packages. It would be helpful for users if you would include all dependencies with this download.

Updates

1.1.1.0

Fixed demo file and imrange dependency. I'm an idiot.

1.1.0.0

Added output class flexibility

1.0.0.0

updated docs links

1.0.0.0

updated description

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux