【问题标题】:Is there a iOS Metal value for bt601?bt601 有 iOS Metal 值吗?
【发布时间】:2019-08-18 19:40:30
【问题描述】:

我有示例金属代码,我正在尝试将其转换为 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);
}

【问题讨论】:

标签: ios macos metal compute-shader


【解决方案1】:

这里的意图似乎只是从内核的 RGB 输出中导出单个“亮度”值。在这种情况下,bt601 将是一个三元素向量,其分量是各个通道的所需权重,总和为 1.0。

Rec. 601借值,我们可以这样定义:

float3 bt601(0.299f, 0.587f, 0.114f);

这当然是一个常见的选择。另一种流行的选择使用Rec. 709 标准中的系数。看起来像这样:

float3 bt709(0.212671f, 0.715160f, 0.072169f);

这两个向量都会为您提供一个灰度值,该值近似于线性 sRGB 颜色的亮度。它们中的任何一个是否“正确”取决于您的数据的来源以及您如何进一步处理它。

MetalPerformanceShaders MPSImageThresholdBinary kernel seems to favor the BT.601 values 不论其价值如何。

我建议您查看this answer,了解有关问题的更多详细信息,以及适合使用这些值的条件。

【讨论】:

    猜你喜欢
    • 2020-03-31
    • 1970-01-01
    • 2015-10-16
    • 2016-10-30
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    相关资源
    最近更新 更多