【问题标题】:CIMaskedVariableBlur creates unwanted borderCIMaskedVariableBlur 创建不需要的边框
【发布时间】:2018-05-13 16:55:06
【问题描述】:

我正在使用以下函数来模糊具有深度图的图像,并注意到过滤器在最终结果图像周围创建了一个边框。我不确定我做错了什么导致了这个。

func blur(image: CIImage, mask: CIImage,orientation: UIImageOrientation = .up) -> UIImage? {

    let invertedMask = mask.applyingFilter("CIColorInvert")
    let output = image.applyingFilter("CIMaskedVariableBlur", parameters: ["inputMask" : invertedMask,"inputRadius": 15.0])

    guard let cgImage = context.createCGImage(output, from: output.extent) else {
        return nil
    }

    return UIImage(cgImage: cgImage, scale: 1.0, orientation: orientation)
}

【问题讨论】:

    标签: ios ciimage


    【解决方案1】:

    我想你可能想说:

    func blur(image: CIImage, mask: CIImage, orientation: UIImageOrientation = .up) -> UIImage? {
    
        let invertedMask = mask.applyingFilter("CIColorInvert")
        let output = image.applyingFilter("CIMaskedVariableBlur", parameters: ["inputMask" : invertedMask,"inputRadius": 15.0])
    
        guard let cgImage = context.createCGImage(output, from: image.extent) else {
            return nil
        }
    
        return UIImage(cgImage: cgImage, scale: 1.0, orientation: orientation)
    }
    

    您在原始图像范围内绘制的位置。 CIMaskedVariableBlur 将设置范围以包括所有采样的像素,这可能包括您不关心的像素,特别是在颜色值与原始图像边界之外的值进行平均的边缘。

    【讨论】:

    • 是的,结果更好,但边缘仍然有一点边框(可能大约 3 像素厚)。知道如何才能完全摆脱它
    • 你这个摇滚人,有完全相同的问题,你的回答完全解决了它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 2010-11-05
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    • 2019-03-13
    • 2012-08-30
    相关资源
    最近更新 更多