Swift 将图像乘以标量
我正在使用一个Swift 将图像乘以标量,swift,core-image,cifilter,ciimage,Swift,Core Image,Cifilter,Ciimage,我正在使用一个CIImage,我需要通过减去128,然后除以每个像素128来规范化它。我该如何使用CIFilter来实现这一点?我不确定这是否有效,但也许您可以使用静态颜色应用两个混合过程,如下所示: let gray = CIImage(color: .gray) // this should be 50% white, or 128/255 let subtracted = CIBlendKernel.subtract.apply(foreground: gray, background:
CIImage
,我需要通过减去128,然后除以每个像素128来规范化它。我该如何使用CIFilter
来实现这一点?我不确定这是否有效,但也许您可以使用静态颜色应用两个混合过程,如下所示:
let gray = CIImage(color: .gray) // this should be 50% white, or 128/255
let subtracted = CIBlendKernel.subtract.apply(foreground: gray, background: inputImage)!
let normalized = CIBlendKernel.divide.apply(foreground: gray, background: subtracted)
请记住,您需要将CIContext的工作格式设置为支持负值的格式。您可以在vImage中实现这一点(假设您的源像素是
UInt8
,目标像素是Float
),但使用数学从0…255转换为-1…1,请使用查找表:
Float
值的查找表UInt8
像素填充目标您可以将所有代码包装在
ciimageprocessornel
中,以将其集成到CI工作流中。请参阅:。这可能会导致负值。你确定这就是你想要实现的吗?@FrankSchlegel是的