在 Photoshop 中比较像素值

发布于 2024-12-15 09:18:32 字数 416 浏览 1 评论 0原文

我想做一些 Photoshop javascript。从技术上讲,我只需要知道如何比较像素 af 的颜色值,如果它们是一个数组,每个像素包含三个整数值,例如:(伪代码)

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

在文档中,有很多东西,例如过滤器,文本和图层可以做,但是这么简单的事情怎么做呢?

i want to make a little photoshop javascript. Technically, i just need to know how to compare the color values of pixels af if they were an array with three integer values in each, for example: (pseudocode)

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

in the documentation, there's a ton of things like filters, text and layers you can do, but how do you do something as simple as this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖树树初阳… 2024-12-22 09:18:32

在 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 脚本不是像素操作的最佳工具......

Reading and writing pixel values in Photoshop scripts is indeed not as simple as it could be ... Check out the following script which inverts the blue channel of an image:

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);

    }
}

I'm not sure if there's a prettier way of setting a pixel color than the select + fill trick.

This script runs super slow, so maybe Photoshop scripts are not the best tool for pixel manipulation ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文