ios - CoreImage CIColorClamp 调整为错误值
问题描述
我正在图像上尝试 CIColorClamp,它应该只将像素保持在指定范围内(https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/ uid/TP30000136-SW42 ) ,但是当我在黑色像素上打印前后结果时,它给出的数字与我在参数中设置的数字不同。这是代码:
let ciImage = CIImage.init(cgImage: image.cgImage!)
let filter = CIFilter("CIColorClamp")!
filter.setDefaults()
filter.setValue(ciImage, forKey: kCIInputImageKey)
filter.setValue(CIVector(x: 0.8, y: 0.8, z: 0.8, w: 0), forKey: "inputMinComponents")
filter.setValue(CIVector(x: 1, y: 1, z: 1, w: 1), forKey: "inputMaxComponents")
let outputCIImage = filter.outputImage!
let context = CIContext.init()
let outputCGImage = context.createCGImage(outputCIImage, from: outputCIImage.extent)
let outputImage = UIImage(cgImage: outputCGImage, scale: image.scale, orientation: image.imageOrientation)
这应该在黑色像素 (0, 0, 0, 1) 上给出 (0.8, 0.8, 0.8, 1),但是当我打印它时,它会给出以下内容:
<CIColorClamp: inputImage=<CIImage: 0x28165d590 extent [0 0 800 160]>
inputMinComponents=[0.8 0.8 0.8 0] inputMaxComponents=[1 1 1 1]>
BEFORE 0.0, 0.0, 0.0, 1.0
AFTER 0.9058823529411765, 0.9058823529411765, 0.9058823529411765, 1.0
CoreImage 是否在做其他事情,然后只是最小/最大?或者我不知道这里还有什么问题。
解决方案
估计是配色问题。Core Image 默认执行从输入到工作到输出颜色空间的颜色匹配。如果输入图像的颜色空间与输出颜色空间不同,您可能会得到不同的像素值。
CIContext
尝试以根本不进行任何颜色匹配的方式设置您的:
let context = CIContext(options: [.workingColorSpace: NSNull(), .outputColorSpace: NSNull()])
对于颜色钳位过滤器,这可能会起作用,因为它只是钳位值。不过,我不确定颜色矩阵过滤器是否需要一些特定的颜色空间。
您还可以 outputCIImage
在调试器中执行快速查看,以查看 Core Image 实际在图像上执行的操作图。
推荐阅读
- c++ - 带有信号处理的 Valgrind
- reactjs - 为什么尝试使用antd文件上传组件时e.target.files未定义?
- php - WordPress 静态主页和自定义博客页面
- php - php imagick 抛出“未捕获的 ImagickException:无法打开文件”
- python - 根据 pth 百分位阈值过滤两个 numpy 数组
- elasticsearch - 3005: disable to convert [0.5] to long 你要怎么解决?
- javascript - 如何在html中设置特定行的样式
- java - 使用 docx4j XHTMLImporterImpl 后 HTML 不保持格式
- jenkins - 用于连接 Amazone EKS 的 Jenkins 代理不起作用
- javascript - 每次单击时为新的 SVG 多边形设置动画的 Javascript