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.
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 works with Image3D objects.
- The following options can be specified:
-
Interleaving True whether to assume channels are interleaved Masking All region of interest to be processed - With InterleavingTrue, the function f is applied to the complete list of channel values for a given pixel; otherwise, f is applied to individual channel values.
Examples
open all close allBasic Examples (2)
Apply a pure function defined on the pixel's value and position:
ImageApplyIndexed[#1 + Max[#2] / 300&, [image]]Apply a function depending on the pixel's values and position to a list of images:
ImageApplyIndexed[Function[{pixel1, pixel2, pixel3, pixel4, pos},
Which[
Max[pos] < 100, pixel1 + .2,
Max[pos] > 150, (pixel1 + pixel2 + pixel3) / 3,
EuclideanDistance[pos, {125, 125}] < 20, .75 - pixel4,
True, 1 - pixel3]],
{[image], [image], [image], Graphics@Disk[]}]Scope (3)
Darken each pixel in an image irrespective of its position:
ImageApplyIndexed[#1 - 0.2&, [image]]Define luminance based on the pixel positions irrespective of their values:
ImageApplyIndexed[Max[#2] / 100&, [image]]Negate pixels of the third slice of a 3D image:
ImageApplyIndexed[If[#2[[1]] == 3, 1 - #1, #1]&, [image]]Options (3)
Interleaving (2)
Use Interleaving->False when the function should be applied to color channels separately:
f[x_Real, pos_] := Piecewise[{{2x, x <= .5}, {2 - 2x, x > .5}}] * Total[pos] / 200
ImageApplyIndexed[f, [image], Interleaving -> False]Use Interleaving->False and a list of images when the function expects separate channel values:
f[x1_Real, x2_Real, pos_] := With[{x = Max[x1, x2]}, Piecewise[{{2x, x <= .5}, {2 - 2x, x > .5}}] * Total[pos] / 200]
ImageApplyIndexed[f, {[image], [image]}, Interleaving -> False]Applications (6)
Create a five-channel image where each resulting pixel represents a combination of RGB color and position:
img = [image];ImageApplyIndexed[Flatten[{#1, #2}]&, img]Normalize positions to be between 0 and 1 in each dimension:
ImageApplyIndexed[Flatten[{#1, #2 / ImageDimensions[img]}]&, img]Use pixel indices to add a 2D cosine wave to an image:
ImageApplyIndexed[#1 + Total[Cos[#2 2π / 30]] / 5&, [image]]Use pixel positions to process each image quadrant differently:
img = [image];
{w, h} = ImageDimensions[img];
f[pixel_, pos : {row_, column_}] :=
Which[
1 <= row < h / 2 && 1 ≤ column < w / 2, pixel,
row ≥ h / 2 && 1 ≤ column < w / 2, pixel - .2,
1 <= row < h / 2 && column ≥ w / 2, pixel + .4,
True, 1 - pixel
];ImageApplyIndexed[f, img]Convert the image to grayscale as gradually moving from the center to the corners:
image = [image];f = Compile[{{pixel, _Real, 1}, {pos, _Integer, 1}, {dim, _Integer, 1}, {γ, _Real}},
Module[{ρ, α},
ρ = Norm[pos - Reverse[dim] / 2] / (Sqrt[Plus@@(dim ^ 2)] / 2);
α = ρ ^ γ;
(1 - α) * pixel + α * Mean[pixel]
]
];
ImageApplyIndexed[f[#1, #2, ImageDimensions[image], 1]&, image]Vary the exponential rate of grayscale conversion:
Table[ImageApplyIndexed[f[#1, #2, ImageDimensions[image], γ]&, image], {γ, {.5, 1, 1.5}}]Colorize an image where hue and saturation depend on the pixel's position and the brightness depends on the pixel value:
Image[ImageApplyIndexed[{First[#2] / 256, Last[#2] / 256, #1}&, [image]], ColorSpace -> "HSB"]Create a filled gradient image by interpolating colors at the corners:
colors = List@@@{Red, Green, Blue, Yellow};funcs = Table[
Interpolation[N@MapThread[{#1, #2}&, {{{1, 1}, {1, 200}, {200, 1}, {200, 200}}, colors[[All, i]]}], InterpolationOrder -> 1], {i, 3}];
Table[ImageApplyIndexed[f[Sequence@@#2]#1&, [image]], {f, funcs}]//ColorCombinePossible Issues (1)
With Interleaving->False, all images should have the same number of channels:
ImageApplyIndexed[Max[{#1, #2}]&, {[image], [image]}, Interleaving -> False]Convert the single-channel image to an RGB image:
ImageApplyIndexed[Max[{#1, #2}]&, {[image], [image]}, Interleaving -> True]See Also
Related Guides
History
Text
Wolfram Research (2014), ImageApplyIndexed, Wolfram Language function, https://reference.wolfram.com/language/ref/ImageApplyIndexed.html.
CMS
Wolfram Language. 2014. "ImageApplyIndexed." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ImageApplyIndexed.html.
APA
Wolfram Language. (2014). ImageApplyIndexed. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ImageApplyIndexed.html
BibTeX
@misc{reference.wolfram_2026_imageapplyindexed, author="Wolfram Research", title="{ImageApplyIndexed}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/ImageApplyIndexed.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_imageapplyindexed, organization={Wolfram Research}, title={ImageApplyIndexed}, year={2014}, url={https://reference.wolfram.com/language/ref/ImageApplyIndexed.html}, note=[Accessed: 13-June-2026]}