QC 组合将黑色和白色像素转换为其他两种颜色

发布于 2024-10-21 16:30:34 字数 315 浏览 0 评论 0原文

我刚刚开始学习 Quartz Composer,我想要创建的第一件事是最终可以在 Cocoa 应用程序中使用的组合,该应用程序将接受黑白图像和两个 NSColor,并将黑色像素更改为 NSColor # 1 和 NSColor #2 的白色像素。

我花了一些时间研究 QC,但似乎无法弄清楚如何将所有部分组合在一起。

我唯一想到的是我需要使用图像过滤器模板,并且我确实看到有一个图像像素补丁可以从图像中获取像素...但是,我没有看到用于设置像素的补丁像素。 Pixellate 补丁似乎也是必要的……不过,我不必担心它会生成无限尺寸的图像,因为我的源图像只是固定大小的 PNG 图像。

I'm just starting to learn about Quartz Composer and the first thing I would like to create is a composition that could eventually be used in a Cocoa application which would accept a black and white image and two NSColor's and change the black pixels to NSColor #1 and the white pixels to NSColor #2.

I've spent some time playing with QC, but cannot seem to figure out how to put all of the pieces together.

About the only thing I have figured out is that I need to use the Image Filter template and I do see there is a Image Pixel patch that can get pixels from an image...however, I don't see a patch to set a pixel. It also seems possible the Pixellate patch might be necessary...although, I shouldn't have to worry about it producing an image with infinite dimensions since my source images will only be fixed size PNG images.

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

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

发布评论

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

评论(1

剩余の解释 2024-10-28 16:30:34

看一下False Color 补丁 - 它获取图像并用一对颜色重新映射它。

事实上,由于 False Color 补丁只是具有相同名称 (CIFalseColor) 的 Core Image 过滤器的包装,因此您可以在不涉及 Quartz Composer 的情况下完成此操作 - -- 只需设置一个 CIFilter 实例并将其应用到您的 NSImage 即可。

编辑 - 或编写您自己的核心图像过滤器,从以下内容开始:

kernel vec4 remapBasedOnRed(sampler image,__color colorForDark,__color colorForLight)
{
    return mix(colorForDark,colorForLight,sample(image, samplerCoord(image)).r);
}

...它获取输入图像的红色通道的亮度 (sample(image, samplerCoord(image)).r ),并将其用作 colorForDarkcolorForLight 之间线性插值的系数。

Take a look at the False Color patch — it takes an image and remaps it with a pair of colors.

In fact, since the False Color patch is just a wrapper around the Core Image filter with the same name (CIFalseColor), you could do this without involving Quartz Composer at all --- just set up and apply a CIFilter instance to your NSImage.

Edit — or write your own Core Image filter, starting with something like this:

kernel vec4 remapBasedOnRed(sampler image,__color colorForDark,__color colorForLight)
{
    return mix(colorForDark,colorForLight,sample(image, samplerCoord(image)).r);
}

...which takes the brightness of the red channel of the input image (sample(image, samplerCoord(image)).r), and uses it as a coefficient for linear interpolation between colorForDark and colorForLight.

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