【问题标题】:Filtering Interpolation method for Core Image sampler核心图像采样器的滤波插值方法
【发布时间】:2017-05-06 21:44:59
【问题描述】:

我正在使用 Core Image 来实现我的自定义图像处理过滤器。内核有两个输入采样器参数:

kernel vec4 filterk(sampler image, sampler db)

最后一个采样器是一个查找表,不希望发生数据突变。 当我从 db sampler 检索值时,似乎应用了一些插值。

我已经使用 OpenGL 着色器在 Android 上实现了这个过滤器并设置了过滤模式 GL_NEAREST:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

设置这些参数后一切正常(设置 GL_LINEAR 时相反)。

这里documentation 表示 CISampler 的默认插值是双线性插值,并且还存在最近邻。

如何在 iOS SDK 上创建 CISampler 并将插值方法设置为最近邻?

附: 此外,Core Image Kernel Language documentation 说有一个 __table 关键字,它使采样器用作查找表。但是XCode在使用这个关键字时会报错:unknown type name '__table'。

附言

尝试使用 initWithTexture 创建 CIImage 并使用过滤属性已设置为 GL_NEAREST 的纹理。这也不起作用documentation 说 CIImage 会忽略过滤和包装模式,因为 CISampler 会覆盖它们。

【问题讨论】:

    标签: ios macos cocoa core-image


    【解决方案1】:

    您需要使用 iOS 上不可用的 CISampler 类:Open Radar。这意味着此时无法指定插值。

    在 Mac OS X 上(或当该类在 iOS 上可用时),您可以为 CISampler 的 kCISamplerFilterMode 选项键指定 kCISamplerFilterNearest。见CISampler Documentation

    例子:

    CISampler* src = [CISampler samplerWithImage:inputImage options:
                      [NSDictionary dictionaryWithObjectsAndKeys:kCISamplerFilterNearest, kCISamplerFilterMode, nil]];
    

    【讨论】:

    • 似乎 CISampler 不适用于 iOS SDK。你试过这个吗?
    • 抱歉,我应该更好地查看文档。请查看更新的答案。
    • 感谢您的回答!
    • 没问题。如果这回答了您的问题,请接受它,谢谢。
    • CISampler 现在在 iOS 9.0 及更高版本中可用。答案需要对此进行编辑;)developer.apple.com/library/ios/documentation/GraphicsImaging/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 1970-01-01
    相关资源
    最近更新 更多