1

我正在使用 Core Image 过滤器并尝试制作 CIEdgeWork 过滤器。应用滤镜后,图像变黑。我是否正确初始化 CIFilter。

 CIFilter *edgeWork = [CIFilter filterWithName:@"CIEdgeWork"
                                       keysAndValues:kCIInputImageKey,filterPreviewImage,
                             @"inputRadius",[NSNumber numberWithFloat:3.0],
                             nil];
4

2 回答 2

3

从 iOS 5.x 开始, CIEdgeWork在 iOS 上的 Core Image 中不可用,因此在尝试使用它时看到黑色图像也就不足为奇了。

但是,您可以使用我的GPUImage框架中的 GPUImageSketchFilter 或 GPUImageThresholdEdgeDetection 来实现相同的效果。您可以在此答案中看到第一个过滤器的结果。后一种过滤器可能更接近 Apple 通过 CIEdgeWork 提供的实际效果,因为它们似乎对生成的边缘检测图像进行了二值化。

于 2012-08-05T22:41:43.077 回答
1

现在 CIEdgeWork 和 CILineOverlay 可用于 iOS9

CIEdgeWork

您还可以使用基于 GPUImageSketchFilter 的 CoreImage 过滤器 Sobel Sketch。 FWKSketchFilter

它的内核:

kernel vec4 sketch(sampler image, float strength){
vec2 d = destCoord();

vec2 bottomLeftTextureCoordinate = samplerTransform(image, d + vec2(-1.0, -1.0));
vec2 topRightTextureCoordinate = samplerTransform(image, d + vec2(1.0, 1.0));
vec2 topLeftTextureCoordinate = samplerTransform(image, d + vec2(-1.0, 1.0));
vec2 bottomRightTextureCoordinate = samplerTransform(image, d + vec2(1.0, -1.0));

vec2 leftTextureCoordinate = samplerTransform(image, d + vec2(-1.0, 0.0));
vec2 rightTextureCoordinate = samplerTransform(image, d + vec2(1.0, 0.0));
vec2 bottomTextureCoordinate = samplerTransform(image, d + vec2(0.0, -1.0));
vec2 topTextureCoordinate = samplerTransform(image, d + vec2(0.0, 1.0));

float bottomLeftIntensity = sample(image, bottomLeftTextureCoordinate).r;
float topRightIntensity = sample(image, topRightTextureCoordinate).r;
float topLeftIntensity = sample(image, topLeftTextureCoordinate).r;
float bottomRightIntensity = sample(image, bottomRightTextureCoordinate).r;

float leftIntensity = sample(image, leftTextureCoordinate).r;
float rightIntensity = sample(image, rightTextureCoordinate).r;
float bottomIntensity = sample(image, bottomTextureCoordinate).r;
float topIntensity = sample(image, topTextureCoordinate).r;

float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;

float mag = 1.0 - (length(vec2(h, v))*strength);

return vec4(vec3(mag), 1.0);}
于 2016-08-04T20:24:39.863 回答