### 32.3 Representing Images

In general Octave supports four different kinds of images, gray-scale images, RGB images, binary images, and indexed images. A gray-scale image is represented with an M-by-N matrix in which each element corresponds to the intensity of a pixel. An RGB image is represented with an M-by-N-by-3 array where each 3-vector corresponds to the red, green, and blue intensities of each pixel.

The actual meaning of the value of a pixel in a gray-scale or RGB image depends on the class of the matrix. If the matrix is of class `double` pixel intensities are between 0 and 1, if it is of class `uint8` intensities are between 0 and 255, and if it is of class `uint16` intensities are between 0 and 65535.

A binary image is an M-by-N matrix of class `logical`. A pixel in a binary image is black if it is `false` and white if it is `true`.

An indexed image consists of an M-by-N matrix of integers and a C-by-3 color map. Each integer corresponds to an index in the color map, and each row in the color map corresponds to an RGB color. The color map must be of class `double` with values between 0 and 1.

— Function File: [img, map] = gray2ind (I, n)

> Convert a gray scale intensity image to an Octave indexed image. The indexed image will consist of n different intensity values. If not given n will default to 64.

— Function File: ind2gray (x, map)

> Convert an Octave indexed image to a gray scale intensity image. If map is omitted, the current colormap is used to determine the intensities.

> See also: gray2ind, rgb2ntsc, image, colormap.

— Function File: [x, map] = rgb2ind (rgb)
— Function File: [x, map] = rgb2ind (R, G, B)

> Convert an RGB image to an Octave indexed image.

> See also: ind2rgb, rgb2ntsc.

— Function File: rgb = ind2rgb (x, map)
— Function File: [R, R, R] = ind2rgb (x, map)

> Convert an indexed image to red, green, and blue color components. If the colormap doesn't contain enough colors, pad it with the last color in the map. If map is omitted, the current colormap is used for the conversion.

> See also: rgb2ind, image, imshow, ind2gray, gray2ind.

— Function File: colormap (map)
— Function File: colormap ("default")

> Set the current colormap.

> `colormap (`map`)` sets the current colormap to map. The color map should be an n row by 3 column matrix. The columns contain red, green, and blue intensities respectively. All entries should be between 0 and 1 inclusive. The new colormap is returned.

> `colormap ("default")` restores the default colormap (the `jet` map with 64 entries). The default colormap is returned.

> With no arguments, `colormap` returns the current color map.

> See also: jet.

— Function File: map = autumn ()
— Function File: map = autumn (n)

> Create color colormap. This colormap ranges from red through orange to yellow. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = bone ()
— Function File: map = bone (n)

> Create color colormap. This colormap varies from black to white with gray-blue shades. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = cool ()
— Function File: map = cool (n)

> Create color colormap. The colormap varies from cyan to magenta. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = copper ()
— Function File: map = copper (n)

> Create color colormap. This colormap varies from black to a light copper tone. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = flag ()
— Function File: map = flag (n)

> Create color colormap. This colormap cycles through red, white, blue and black with each index change. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = gray ()
— Function File: map = gray (n)

> Create gray colormap. This colormap varies from black to white with shades of gray. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

— Function File: map = hot ()
— Function File: map = hot (n)

> Create color colormap. This colormap ranges from black through dark red, red, orange, yellow, to white. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: hsv (n)

> Create color colormap. This colormap begins with red, changes through yellow, green, cyan, blue, and magenta, before returning to red. It is useful for displaying periodic functions. It is obtained by linearly varying the hue through all possible values while keeping constant maximum saturation and value and is equivalent to `hsv2rgb ([linspace(0,1,N)', ones(N,2)])`.

> The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = jet ()
— Function File: map = jet (n)

> Create color colormap. This colormap ranges from dark blue through blue, cyan, green, yellow, red, to dark red. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = ocean ()
— Function File: map = ocean (n)

> Create color colormap. This colormap varies from black to white with shades of blue. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

— Function File: map = pink ()
— Function File: map = pink (n)

> Create color colormap. This colormap varies from black to white with shades of gray-pink. It gives a sepia tone when used on grayscale images. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = prism ()
— Function File: map = prism (n)

> Create color colormap. This colormap cycles through red, orange, yellow, green, blue and violet with each index change. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = rainbow ()
— Function File: map = rainbow (n)

> Create color colormap. This colormap ranges from red through orange, yellow, green, blue, to violet. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = spring ()
— Function File: map = spring (n)

> Create color colormap. This colormap varies from magenta to yellow. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = summer ()
— Function File: map = summer (n)

> Create color colormap. This colormap varies from green to yellow. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: map = white ()
— Function File: map = white (n)

> Create color colormap. This colormap is completely white. The argument n should be a scalar. If it is omitted, the length of the current colormap or 64 is assumed.

> See also: colormap.

— Function File: map = winter ()
— Function File: map = winter (n)

> Create color colormap. This colormap varies from blue to green. The argument n must be a scalar. If unspecified, the length of the current colormap, or 64, is used.

> See also: colormap.

— Function File: contrast (x, n)

> Return a gray colormap that maximizes the contrast in an image. The returned colormap will have n rows. If n is not defined then the size of the current colormap is used instead.

> See also: colormap.

An additional colormap is `gmap40`. This code map contains only colors with integer values of the red, green and blue components. This is a workaround for a limitation of gnuplot 4.0, that does not allow the color of line or patch objects to be set, and so `gmap40` is useful for gnuplot 4.0 users, and in particular in conjunction with the bar, barh or contour functions.

— Function File: map = gmap40 ()
— Function File: map = gmap40 (n)

> Create color colormap. The colormap consists of red, green, blue, yellow, magenta and cyan. This colormap is specifically designed for users of gnuplot 4.0 where these 6 colors are the allowable ones for patch objects. The argument n must be a scalar. If unspecified, a length of 6 is assumed. Larger values of n result in a repetition of the above colors.

> See also: colormap.

The following three functions modify the existing colormap rather than replace it.

— Function File: map_out = brighten (map, beta)
— Function File: map_out = brighten (h, beta)
— Function File: map_out = brighten (beta)

> Darken or brighten the given colormap. If the map argument is omitted, the function is applied to the current colormap. The first argument can also be a valid graphics handle h, in which case `brighten` is applied to the colormap associated with this handle.

> Should the resulting colormap map_out not be assigned, it will be written to the current colormap.

> The argument beta should be a scalar between -1 and 1, where a negative value darkens and a positive value brightens the colormap.

> See also: colormap.

— Function File: spinmap (t, inc)

> Cycle the colormap for t seconds with an increment of inc. Both parameters are optional. The default cycle time is 5 seconds and the default increment is 2.

> A higher value of inc causes a faster cycle through the colormap.

> See also: gca, colorbar.

— Function File: whitebg ()
— Function File: whitebg (color)
— Function File: whitebg ("none")
— Function File: whitebg (fig)
— Function File: whitebg (fig, color)
— Function File: whitebg (fig, "none")

> Invert the colors in the current color scheme. The root properties are also inverted such that all subsequent plot use the new color scheme.

> If defined, fig is the handle to the figure to be inverted. In this case only the specified figure has its color properties changed.

> If the optional argument color is present then the background color is set to color rather than inverted. color may be a string representing one of the eight known colors or an RGB triplet. The special string argument "none" restores the plot to the default colors.

> See also: reset.