Image

Image[data]

represents a raster image with pixel values given by the array data.

Image[graphics]

creates a raster image from a graphics object.

Image[obj,options]

gives an image that uses the specified options.

Details and Options

  • Image[] displays in a notebook as an image.
  • Image[data] arranges successive rows of data down the page, and successive columns across.
  • In Image[data], each element of data can specify values for any number of channels.
  • Elements of data can be either of the following:
  • vrendered as gray level from 0 (black) to 1 (white)
    {r,g,b}rendered as red, green, blue values from 0 to 1
    {c1,c2,c3,}channel values rendered by equally spaced hues
    colorspecific color
  • The input array data can be given as a List, NumericArray, SparseArray, etc.
  • Image[data] by default allows any real number, but displays only values between 0 and 1.
  • Image[data,"type"] can be used to create an image of a specified data type. Values in data are coerced to the specified type by rounding or clipping. By default, "Real32" is assumed.
  • Possible settings for "type" include:
  • "Bit"integer 0 or 1
    "Byte"integer 0 through 255
    "Bit16"integer 0 through 65535
    "Real32"single-precision real (32 bit)
    "Real64"double-precision real (64 bit)
  • Image[image,"type"] can be used to convert between types.
  • Image is treated as a raw object by functions like AtomQ, and for purposes of pattern matching.
  • The following options can be specified:
  • AlignmentPointCenterthe default point in the graphic to align with
    BaselinePositionAutomatichow to align with a surrounding text baseline
    ColorSpaceAutomaticwhat color space to assume for the data
    ImageResolutionAutomaticthe resolution when displayed or exported
    ImageSizeAutomaticdisplay size of the image
    InterleavingAutomaticwhether to assume channels are interleaved
    MagnificationAutomatichow to magnify the displayed image
    MetaInformation<||>metainformation associated with the image
  • ColorSpace->cs specifies that values in the data should be interpreted as coordinates in a particular color space cs. ColorSpace->Automatic treats values as arbitrary channel intensities.
  • Image[graphics] effectively uses Rasterize[graphics,"Image"] to rasterize graphics.
  • Image[Raster[]] converts a Raster object to an image.
  • Image[Image[],opts] effectively resets the options for an image.
  • ImageDimensions, ImageChannels and ImageType find information on the structure of an image.
  • Arithmetic and statistical operations such as Log, Plus and Mean can work directly with images.
  • Information for Image may include the following properties:
  • "Channels"number of image channels
    "ColorSpace"the color space to assume for data
    "DataType"underlying data type
    "ImageDimensions"pixel dimensions
    "Interleaving"whether data is stored interleaved
    "Transparency"whether the image has transparency (alpha) channel

Background & Context

  • Image provides unified symbolic representation for a large variety of digital image formats (e.g. GIF, PNG, JPG) as found on the internet and elsewhere. In particular, an Image object contains a two-dimensional array of values (or lists of values) that represents a raster image. Images are commonly encountered in digital photography, digitization of text and pictures, scientific visualization, and a wide variety of other fields. The data inside an image may take on a variety of values depending on if the image is binary, grayscale, RGB, CMYK, includes an alpha channel, etc.
  • Upon output, an Image formats as a picture of the actual image, not as a 2D array of values. Image objects may be exported to a variety of standard image formats using Export, and images in a number of formats may be imported as Image objects using Import. Image objects may also be inserted into a notebook by drag-and-drop from external applications.
  • An arbitrary Graphics expression may be converted to an image by applying the function Image to it. Similarly, an image may be converted to a raster expression suitable for display with other Graphics primitives by applying Raster to it. The function Show can be used to combine 2D vector graphics (or Graphics objects) with Image objects.
  • The array of pixel values in an image may be obtained using ImageData. ImageDimensions gives the pixel dimensions of the raster associated with an Image object. ImageType gives a label representing the number type used internally to represent each pixel of an image. Image itself can be used to convert between image types, and ImageAdjust can be used to bring all values of a real-valued image into the range 0 to 1. The number of channels the image contains may be obtained using the function ImageChannels.
  • Options useful for Image objects include ColorSpace, Interleaving, ImageResolution, ImageSize, and Magnification.

Examples

open allclose all

Basic Examples  (3)

Create an image from a 3×3 array:

Create an RGB channel image from a 3D array:

Create an image by importing from a file:

Get information about the image:

Scope  (18)

Basic Uses  (3)

Import an image:

Change the image type from 8-bit integer to a 64-bit real:

Convert a graphic to a bitmap image:

Creating an Image  (11)

Import from a file:

Create from a region:

Create a grayscale image from a 2D array of data:

By default, data is assumed to be 0 to 1 and an image of type "Real32" is generated:

Create a color image from a 3D array of data:

Create an image from an array of colors:

Create an image of type "Byte":

Create a binary image from a 3×3 array:

Create an image from a SparseArray object:

Create a raster image from a Graphics object:

Create an image from a Graphics3D object:

Create an image from a GeoGraphics object:

Arithmetic & Statistical Operations  (4)

Create a linear combination of two images:

Highlight edges in an image:

Compute statistical measures on images:

The value of a system option "IndeterminateValue" is used to replace values that cannot be stored in an image including ComplexInfinity and Indeterminate.

By default, 0 is used:

See the behavior using power:

Change the current value of the "IndeterminateValue" option:

Reset to the default 0:

Options  (21)

ColorSpace  (8)

By default, when generating images from data, no specific color space is assumed:

Check for the color space of an image with ImageColorSpace:

Specify the color space:

Generate a random RGB color image:

Random RGB image with alpha channel:

Generate a random gray-level image:

Random gray-level image with alpha channel:

Random CMYK image:

A CIE XYZ image:

Images with an arbitrary number of channels are stored with ColorSpace->Automatic:

Image channels should match the number of channels expected by the color space:

Change the interpretation of the pixel values in an image:

Use ColorConvert to convert the pixel values to a new space:

ImageResolution  (3)

At the default magnification, ImageResolution72 means that 72 pixels will occupy an inch of the screen:

Changing the resolution affects the full display size of an image:

The value of ImageResolution may be automatically set by some functions:

ImageSize  (3)

Image with an explicit setting for the width:

With ImageSize->Automatic, images may appear larger or smaller than their actual size:

Use ImageSize->All to see images in their actual size:

Set the displayed size of an image:

Specifying both width and height will add white space if aspect ratios do not match:

Interleaving  (3)

By default, interleaved data is assumed:

Use Options to extract the Interleaving setting:

Create an image from planar data:

Image with data stored in three color planes:

Change an interleaved image to planar:

Magnification  (2)

Image with an explicit magnification:

ImageSize and Magnification both control the display size of the image:

When both are set, ImageSize specification is used:

MetaInformation  (2)

Add custom metainformation to an image:

Use Options to extract the metainformation:

Import puts metadata stored in the file into the MetaInformation option:

Applications  (2)

Visualize an evaluation of a cellular automaton using a binary image:

Visualize an elevation map:

Properties & Relations  (8)

Image objects are atoms and cannot be subdivided:

All values below 0 display as black, and values greater than 1 display as white:

For images with out-of-range values, use ImageAdjust to scale all values between 0 and 1:

Different image types use different bit depths. Use smaller bit depth for compression:

Convert a binary image to array rules:

Use Rasterize to create an image from any expression:

Use RandomImage to create an Image with random pixel values:

ConstantImage can generate an Image of a constant color:

LinearGradientImage and RadialGradientImage can be used to create gradient images:

Introduced in 2008
 (7.0)
 |
Updated in 2012
 (9.0)
2014
 (10.0)
2016
 (11.0)
2017
 (11.1)
2019
 (12.0)