metal - 使用减少 CIFilter 的输出作为另一个过滤器的颜色输入
问题描述
我是 CoreImage / Metal 的新手,所以如果我的问题很幼稚,我提前道歉。我花了一周时间浏览 CoreImage 文档和示例,但我无法弄清楚这一点。
假设我有一个缩减过滤器,例如 CIAreaAverage,它输出 1x1 图像。是否可以将该图像转换为可以作为另一个 CIFilter 的参数传递的颜色?我知道我可以通过将 CIAreaAverage 输出渲染到 CVPixelBuffer 来做到这一点,但我试图在一次渲染过程中做到这一点。
编辑#1(澄清):
假设我想通过允许用户从图像中采样一个灰色像素来纠正白平衡:
let pixelImage = inputImage.applyingFilter("CICrop", arguments: [
"inputRectangle": CGRect(origin: pixelCoordinates, size: CGSize(width: 1, height: 1))
])
// We know now that the extent of pixelImage is 1x1.
// Do something to convert the image into a pixel to be passed as an argument in the filter below.
let pixelColor = ???
let outputImage = inputImage.applyingFilter("CIWhitePointAdjust", arguments: [
"inputColor": pixelColor
])
有没有办法告诉CIContext
1x1CIImage
转换成CIColor
?
解决方案
如果您想CIAreaAverage
在自定义 CIFilter
中使用结果(即您不需要它作为CIColor
参数),您可以直接将其作为 a 传递给该过滤器并通过内核CIImage
读取值:sampler
extern "C" float4 myKernel(sampler someOtherInput, sampler average) {
float4 avg = average.sample(float2(0.5, 0.5)); // average only contains one pixel, so always sample that
// ...
}
您还可以在将平均值传递给另一个过滤器/内核之前调用.clampedToExtent()
平均值。CIImage
这将导致 Core Image 将平均图像视为无限大,在任何地方都包含相同的值。然后在哪个坐标对值进行采样并不重要。如果您想在自定义中使用平均值,这可能很有用CIColorKernel
。
推荐阅读
- python - 如何在类和方法中获取python变量
- amazon-web-services - AWS SNS ConfirmSubscription 授权从未授予 IAM 用户
- python - 根据数据库字段计算算术平均值?(直接来自 Python,不使用 sql)
- python - Python 正则表达式匹配以 word 开头、以 4 位数字结尾、除 @ 和 % 外不包含特殊字符且至少有 10 个字符的模式
- javascript - 如何使用 jQuery 自动计算 html 表?
- shell - 如何在 zsh 中读入睡眠
- json - Talend ETL 作业后 Elasticsearch 中的记录丢失
- android - 我正在尝试显示此聊天应用程序的主屏幕并添加消息发送时间
- rust - 使用 nom 读取二进制 u32
- vue.js - Vue Apollo 上传文件崩溃节点最大调用堆栈大小超过 _openReadFs