CIImage(IOS):在单色滤镜之后添加3×3卷积以某种方式恢复颜色

CIImage(IOS):在单色滤镜之后添加3×3卷积以某种方式恢复颜色,第1张

概述我正在将ciimage转换为单色,使用CICrop进行裁剪 并且运行索贝尔来检测边缘,底部的#if部分是 用来显示结果 CIImage *ci = [[CIImage alloc] initWithCGImage:uiImage.CGImage];CIImage *gray = [CIFilter filterWithName:@"CIColorMonochrome" keysAndValue 我正在将ciimage转换为单色,使用CICrop进行裁剪
并且运行索贝尔来检测边缘,底部的#if部分是
用来显示结果

CIImage *ci = [[CIImage alloc] initWithCGImage:uiImage.CGImage];CIImage *gray = [CIFilter filterWithname:@"CIcolorMonoChrome" keysAndValues:      @"inputimage",ci,@"inputcolor",[[CIcolor alloc] initWithcolor:[UIcolor whitecolor]],nil].outputimage;CGRect rect = [ci extent];rect.origin = CGPointZero;CGRect cropRectleft = CGRectMake(0,rect.size.wIDth * 0.2,rect.size.height);CIVector *cropRect = [CIVector vectorWithX:rect.origin.x Y:rect.origin.y Z:rect.size.wIDth* 0.2 W:rect.size.height];CIImage *left = [gray imageByCropPingToRect:cropRectleft];CIFilter *cropFilter = [CIFilter filterWithname:@"CICrop"];[cropFilter setValue:left forKey:@"inputimage"];[cropFilter setValue:cropRect forKey:@"inputRectangle"];// The sobel convoloution will produce an image that is 0.5,0.5,0.5 whereever the image is flat// On edges the image will contain values that deviate from that based on the strength and// direction of the edgeconst double g = 1.;const CGfloat weights[] = { 1*g,-1*g,2*g,-2*g,1*g,-1*g};left = [CIFilter filterWithname:@"CIConvolution3X3" keysAndValues:      @"inputimage",cropFilter.outputimage,@"inputWeights",[CIVector vectorWithValues:weights count:9],@"inputBias",@0.5,nil].outputimage;#define VISUALHELP 1#if VISUALHELPCGImageRef imageRefleft = [gcicontext createCGImage:left fromrect:cropRectleft];CGContextDrawImage(context,cropRectleft,imageRefleft);CGImageRelease(imageRefleft);#endif

现在每当3×3卷积不是ciimage管道的一部分
我运行边缘检测的图像部分显示为灰色,
但每当CIConvolution3X3后缀是处理管道的一部分
颜色神奇地回来了.这无论如何都会发生
如果我使用CIcolorMonoChrome或CIPhotoEffectMono前缀来删除颜色.
任何想法如何保持颜色一直到管道的底部?
TNX

UPD:毫不奇怪地运行一个原始的自定义单色内核,如这个

kernel vec4 gray(sampler image){    vec4 s = sample(image,samplerCoord(image));    float r = (s.r * .299 + s.g * .587 + s.b * 0.114) * s.a;    s = vec4(r,r,1);    return s;}

而不是使用来自苹果的标准单声道滤波器,结果完全相同
当3×3卷积是我的ci管道的一部分时,颜色回来的问题

解决方法 这个问题是CI卷积运算(例如CIConvolution3X3,CIConvolution5X5和CIGaussianBlur)在输入图像的所有四个通道上运行.这意味着,在您的代码示例中,生成的Alpha通道将为0.5,您可能希望它为1.0.尝试在卷积后添加一个简单的内核,将Alpha设置回1. 总结

以上是内存溢出为你收集整理的CIImage(IOS):在单色滤镜之后添加3×3卷积以某种方式恢复颜色全部内容,希望文章能够帮你解决CIImage(IOS):在单色滤镜之后添加3×3卷积以某种方式恢复颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1072428.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存