ImageApplyIndexed[f,image]
把函数 f 应用于 image 中每个像素的通道值列表上,给出每个像素的行列索引作为 f 的第二个参数.
ImageApplyIndexed[f,{image1,image2,…}]
对从每个 imagei 中获取的相应的像素值序列应用 f,给出每个像素对应的行列索引作为 f 的最后一个参数.
ImageApplyIndexed
ImageApplyIndexed[f,image]
把函数 f 应用于 image 中每个像素的通道值列表上,给出每个像素的行列索引作为 f 的第二个参数.
ImageApplyIndexed[f,{image1,image2,…}]
对从每个 imagei 中获取的相应的像素值序列应用 f,给出每个像素对应的行列索引作为 f 的最后一个参数.
更多信息和选项
- ImageApplyIndexed[f,image] 把每个像素的通道值列表替换为把函数 f 作用于该列表得到的结果.
- 二维情况下,每个像素的部件参数说明以 {row,column} 的形式传递给 f.
- 三维情况下,部件参数说明以 {slice,row,column} 的形式指定.
- ImageApplyIndexed 适用于有任意通道数的图像.
- ImageApplyIndexed[f,image] 返回和 image 同样类型的图像.
- 在 ImageApplyIndexed[f,image] 中,函数 f 可以返回一个数字或一个任意长度的列表.
- 无论被用在 Image 对象中的隐含类型是什么,提供给 f 的通道值都被归一化成大小在 0 和 1 之间的数值. 假定函数 f 返回的通道值也被归一化成大小在 0 和 1 之间的数值.
- 在 ImageApplyIndexed[f,{image1,image2,…,imagen}] 中,提供给 f 的是 n+1 个参数.
- ImageApplyIndexed[f,{image1,image2,…}] 适用于任意数量的一般图像.
- ImageApplyIndexed[f,{image1,image2,…}] 给出的图像是 imagei 的最大类型,有必要时会做剪切或截断.
- ImageApplyIndexed 有选项 Interleaving,指明 f 是应该作用于给定像素的单个通道值,还是所有通道值. 缺省设置为 Interleaving->True.
- ImageApplyIndexed 也适用于 Image3D 对象.
范例
打开所有单元 关闭所有单元基本范例 (2)
ImageApplyIndexed[#1 + Max[#2] / 300&, [image]]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[]}]范围 (3)
选项 (3)
Interleaving (2)
当函数应对不同的颜色通道分别进行处理时,要设置 Interleaving->False:
f[x_Real, pos_] := Piecewise[{{2x, x <= .5}, {2 - 2x, x > .5}}] * Total[pos] / 200
ImageApplyIndexed[f, [image], Interleaving -> False]对于图像列表,函数需要分离的通道值时,设置 Interleaving->False:
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]应用 (6)
生成一个有五个通道的图像,其中,生成的每个像素表示 RGB 颜色和位置的组合:
img = [image];ImageApplyIndexed[Flatten[{#1, #2}]&, img]ImageApplyIndexed[Flatten[{#1, #2 / ImageDimensions[img]}]&, img]ImageApplyIndexed[#1 + Total[Cos[#2 2π / 30]] / 5&, [image]]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]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]Table[ImageApplyIndexed[f[#1, #2, ImageDimensions[image], γ]&, image], {γ, {.5, 1, 1.5}}]将图像进行着色处理,其中,色相和饱和度取决于像素的位置,亮度取决于像素的值:
Image[ImageApplyIndexed[{First[#2] / 256, Last[#2] / 256, #1}&, [image]], ColorSpace -> "HSB"]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}]//ColorCombine可能存在的问题 (1)
在设置 Interleaving->False 下,所有图像应当有同样数量的通道:
ImageApplyIndexed[Max[{#1, #2}]&, {[image], [image]}, Interleaving -> False]ImageApplyIndexed[Max[{#1, #2}]&, {[image], [image]}, Interleaving -> True]相关指南
-
▪
- 基本的图像处理
文本
Wolfram Research (2014),ImageApplyIndexed,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ImageApplyIndexed.html.
CMS
Wolfram 语言. 2014. "ImageApplyIndexed." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/ImageApplyIndexed.html.
APA
Wolfram 语言. (2014). ImageApplyIndexed. Wolfram 语言与系统参考资料中心. 追溯自 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: 30-October-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: 30-October-2026]}