bt601 有 iOS 金属价值吗?
Is there a iOS Metal value for bt601?
我有示例金属代码,我正在尝试将其转换为 iOS。是否有可用于 bt601
的 iOS 兼容值?
#include <metal_stdlib>
#include "utilities.h" // error not found
using namespace metal;
kernel void laplace(texture2d<half, access::read> inTexture [[ texture(0) ]],
texture2d<half, access::read_write> outTexture [[ texture(1) ]],
uint2 gid [[ thread_position_in_grid ]]) {
constexpr int kernel_size = 3;
constexpr int radius = kernel_size / 2;
half3x3 laplace_kernel = half3x3(0, 1, 0,
1, -4, 1,
0, 1, 0);
half4 acc_color(0, 0, 0, 0);
for (int j = 0; j <= kernel_size - 1; j++) {
for (int i = 0; i <= kernel_size - 1; i++) {
uint2 textureIndex(gid.x + (i - radius), gid.y + (j - radius));
acc_color += laplace_kernel[i][j] * inTexture.read(textureIndex).rgba;
}
}
half value = dot(acc_color.rgb, bt601); //bt601 not defined
half4 gray_color(value, value, value, 1.0);
outTexture.write(gray_color, gid);
}
似乎这里的意图只是从内核的 RGB 输出中导出单个 "luminance" 值。在这种情况下,bt601
将是一个三元素向量,其分量是各个通道的所需权重,总和为 1.0。
借用Rec. 601的值,我们可以这样定义:
float3 bt601(0.299f, 0.587f, 0.114f);
这当然是一个常见的选择。另一个流行的选择是使用 Rec. 709 标准中的系数。看起来像这样:
float3 bt709(0.212671f, 0.715160f, 0.072169f);
这两个向量都会为您提供一个近似于线性 sRGB 颜色亮度的灰度值。它们中的任何一个是否 "correct" 取决于您的数据来源以及您如何进一步处理它。
不管它值多少钱,MetalPerformanceShaders MPSImageThresholdBinary
内核 seems to favor the BT.601 values.
我建议查看 this answer 以了解有关问题的更多详细信息,以及适合使用这些值的条件。
我有示例金属代码,我正在尝试将其转换为 iOS。是否有可用于 bt601
的 iOS 兼容值?
#include <metal_stdlib>
#include "utilities.h" // error not found
using namespace metal;
kernel void laplace(texture2d<half, access::read> inTexture [[ texture(0) ]],
texture2d<half, access::read_write> outTexture [[ texture(1) ]],
uint2 gid [[ thread_position_in_grid ]]) {
constexpr int kernel_size = 3;
constexpr int radius = kernel_size / 2;
half3x3 laplace_kernel = half3x3(0, 1, 0,
1, -4, 1,
0, 1, 0);
half4 acc_color(0, 0, 0, 0);
for (int j = 0; j <= kernel_size - 1; j++) {
for (int i = 0; i <= kernel_size - 1; i++) {
uint2 textureIndex(gid.x + (i - radius), gid.y + (j - radius));
acc_color += laplace_kernel[i][j] * inTexture.read(textureIndex).rgba;
}
}
half value = dot(acc_color.rgb, bt601); //bt601 not defined
half4 gray_color(value, value, value, 1.0);
outTexture.write(gray_color, gid);
}
似乎这里的意图只是从内核的 RGB 输出中导出单个 "luminance" 值。在这种情况下,bt601
将是一个三元素向量,其分量是各个通道的所需权重,总和为 1.0。
借用Rec. 601的值,我们可以这样定义:
float3 bt601(0.299f, 0.587f, 0.114f);
这当然是一个常见的选择。另一个流行的选择是使用 Rec. 709 标准中的系数。看起来像这样:
float3 bt709(0.212671f, 0.715160f, 0.072169f);
这两个向量都会为您提供一个近似于线性 sRGB 颜色亮度的灰度值。它们中的任何一个是否 "correct" 取决于您的数据来源以及您如何进一步处理它。
不管它值多少钱,MetalPerformanceShaders MPSImageThresholdBinary
内核 seems to favor the BT.601 values.
我建议查看 this answer 以了解有关问题的更多详细信息,以及适合使用这些值的条件。