并且运行索贝尔来检测边缘,底部的#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管道的一部分时,颜色回来的问题
以上是内存溢出为你收集整理的CIImage(IOS):在单色滤镜之后添加3×3卷积以某种方式恢复颜色全部内容,希望文章能够帮你解决CIImage(IOS):在单色滤镜之后添加3×3卷积以某种方式恢复颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)