ImageApplyIndexed

ImageApplyIndexed[f,image]

applies the function f to the list of channel values for each pixel in image, giving the row and column index of each pixel as a second argument to f.

ImageApplyIndexed[f,{image1,image2,}]

applies f to the sequence of corresponding pixel values taken from each imagei, giving the corresponding row and column index of pixels as the last argument to f.

Details and Options

  • ImageApplyIndexed[f,image] replaces the list of channel values for each pixel by the result of applying the function f to the list.
  • In 2D, the part specification of each pixel is passed to f as {row,column}.
  • In 3D, the part specifications are specified with {slice,row,column}.
  • ImageApplyIndexed works on images with any number of channels.
  • ImageApplyIndexed[f,image] returns an image of the same type as image.
  • In ImageApplyIndexed[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 used in the Image object. The function f is assumed to return channel values that are normally in the range 0 to 1.
  • In ImageApplyIndexed[f,{image1,image2,,imagen}], f is supplied with n+1 arguments.
  • ImageApplyIndexed[f,{image1,image2,}] works with any number of commensurate images.
  • ImageApplyIndexed[f,{image1,image2,}] gives an image with the largest type of imagei, clipping or truncating values if necessary.
  • ImageApplyIndexed has the option Interleaving, which specifies whether f should be applied to individual channel values or to the complete list of channel values for a given pixel. The default setting is Interleaving->True.
  • ImageApplyIndexed works with Image3D objects.

Examples

open allclose all

Basic Examples  (2)

Apply a pure function defined on the pixel's value and position:

Apply a function depending on the pixel's values and position to a list of images:

Scope  (3)

Darken each pixel in an image irrespective of its position:

Define luminance based on the pixel positions irrespective of their values:

Negate pixels of the third slice of a 3D image:

Options  (3)

Interleaving  (2)

Use Interleaving->False when the function should be applied to color channels separately:

Use Interleaving->False and a list of images when the function expects separate channel values:

Masking  (1)

Apply the function to the region of interest specified by a mask:

Applications  (6)

Create a five-channel image where each resulting pixel represents a combination of RGB color and position:

Normalize positions to be between 0 and 1 in each dimension:

Use pixel indices to add a 2D cosine wave to an image:

Use pixel positions to process each image quadrant differently:

Convert the image to grayscale as gradually moving from the center to the corners:

Vary the exponential rate of grayscale conversion:

Colorize an image where hue and saturation depend on the pixel's position and the brightness depends on the pixel value:

Create a filled gradient image by interpolating colors at the corners:

Possible Issues  (1)

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

Convert the single-channel image to an RGB image:

Introduced in 2014
 (10.0)