在Photoshop中比较像素值

3

我希望制作一个小型的Photoshop JavaScript程序。从技术上讲,我只需要知道如何比较像素的颜色值,就好像它们是一个包含三个整数值的数组一样,例如:(伪代码)

for all pixels x
    for all pixels y
        if left pixel's green channel is bigger than red channel:
            set the blue channel to 25
        else
            if the blue channel is greater than 50
                set the green channel to 0

在文档中,有很多类似过滤器、文本和图层的操作,但如何执行这样简单的操作呢?
1个回答

2

在Photoshop脚本中读写像素值确实不像我们想象的那么简单...请查看以下脚本,它可以反转图像的蓝色通道:

var doc = app.open(new File("~/Desktop/test1.bmp"));

var sampler = doc.colorSamplers.add([0, 0]);

for (var x = 0; x < doc.width; ++x) {
    for (var y = 0; y < doc.height; ++y) {        

        sampler.move([x, y]);
        var color = sampler.color;

        var region = [
            [x, y],
            [x + 1, y],
            [x + 1, y + 1],
            [x, y + 1],
            [x, y]
        ];

        var newColor = new SolidColor();
        newColor.rgb.red = color.rgb.red;
        newColor.rgb.green = 255 - color.rgb.green;
        newColor.rgb.blue = color.rgb.blue;

        doc.selection.select(region);
        doc.selection.fill(newColor);

    }
}

我不确定是否有比选择+填充技巧更好的设置像素颜色的方法。
这个脚本运行非常缓慢,可能 Photoshop 脚本并不是处理像素最好的工具...

3
谢谢。关于表现:我太傻了,以为我能用 Photoshop 操纵像素:D。 - Ari Romano Pfefferkorn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接