ImageApply

ImageApply[f,image]

applies the function f to the list of channel values for each pixel in image.

ImageApply[f,{image1,image2,}]

applies f to the sequence of corresponding pixel values taken from each imagei.

Details and Options

  • ImageApply[f,image] replaces the list of channel values for each pixel by the result of applying the function f to the list.
  • ImageApply works with 2D and 3D images with any number of channels.
  • ImageApply[f,image] returns an image of the same type as image.
  • In ImageApply[f,image], the function f can return a number or a list of any length.
  • The channel values supplied to f are normally in the range 0 to 1, regardless of the underlying type of image. The function f is assumed to return channel values that are normally in the range 0 to 1.
  • In ImageApply[f,{image1,,imagen}], f is supplied with n arguments. »
  • ImageApply[f,{image1,image2,}] works with any number of commensurate images and gives an image with the largest type of imagei, clipping or truncating values if necessary.
  • The following options can be given:
  • InterleavingTruewhether to apply f to the list of channel values or separately to each channel value
    MaskingAllregion of interest to be processed
  • Evaluations of f may be cached to focus on speed of getting a result. »

Examples

open allclose all

Basic Examples  (2)

Replace each pixel with the maximum of the color channels:

Compute the average of three color images:

Scope  (8)

Color negate a grayscale image:

Color negate an RGB image:

Reverse the elements of each channel vector:

Replace each RGB pixel by the maximum of all channel values:

Compute the maximum of corresponding pixel values in a list of grayscale images:

Apply a pure function to a sequence of pixel values in a list of RGB-color images:

Apply a function to pixels of a 3D RGB image:

Combine two 3D images:

Options  (4)

Interleaving  (2)

Use Interleaving->False when the function has to be applied to each color channel value separately:

With Interleaving->False, all images should have the same number of channels:

Convert the single-channel image to an RGB image:

Masking  (2)

Negate pixels in the specified region of interest:

Region-of-interest processing is not supported when applying a function to a list of images:

Include the mask as one of the images in the list:

Applications  (10)

Apply a gamma correction:

Color negate the image:

Covert to a single-channel image:

Display a selected channel:

Use built-in color gradients to add color to an image:

Add an alpha channel to a grayscale image:

Highlight a region in an image:

Compute the elementwise inverse of an image:

Pixel-wise division of two images:

Create a saturated composite image:

Colorize the gradient's magnitude and orientation of an image:

Compute the so-called Robert's gradient image:

Properties & Relations  (2)

ImageApply returns an image of the same data type as input:

Clipping and truncation will happen when necessary:

Convert to a real type to avoid clipping and truncating:

In ImageApply[f,image], evaluations of f may be cached to focus on speed of getting a result:

Single channel "Byte" images use cached evaluations:

This may affect the result if the specified function can give different results when applied to same inputs:

Multichannel "Byte" images use cached evaluations with Interleaving->False:

Compare with the timing for an interleaved image when no caching is used:

Multichannel "Byte" images use cached evaluations with Listable functions:

Possible Issues  (3)

Functions that accept lists as their input cannot be applied on single-channel images:

Functions should return a number or a list of numbers for every pixel in the image:

The same inverse function can be applied to an image with nonzero pixels:

ImageApply preserves the image data type, clipping or truncating values if necessary:

Apply the function to a "Real32" image instead:

Neat Examples  (4)

Rotate color channels:

Convert an image to grayscale while preserving the red color:

Apply any coloring function to an image:

Colorize a grayscale image:

Introduced in 2008
 (7.0)
 |
Updated in 2012
 (9.0)