GPUImage铅笔草图过滤器优化

时间:2017-02-24 10:49:12

标签: image-processing uiimage shader gpuimage fragment-shader

我使用GPUImage框架实现了铅笔素描过滤器。但我认为过滤器太复杂而无法产生输出。

  

铅笔过滤功能

php
  

输出图像作为过滤器的结果

enter image description here

请有人建议我如何优化此过滤器? 我想如果有人指导我为此编写着色器程序。我可以制作一个自定义的GPUImageFilter并为其编写着色器程序。

1 个答案:

答案 0 :(得分:3)

UIImage *imgCropped=image;
stillImageSource = [[GPUImagePicture alloc] initWithImage:imgCropped];
saturationFilter=[[GPUImageSaturationFilter alloc]init];
[saturationFilter setSaturation:0];
 [stillImageSource addTarget:saturationFilter];
[stillImageSource processImage];
[saturationFilter useNextFrameForImageCapture];
UIImage *copyImage=[saturationFilter imageFromCurrentFramebuffer];
stillImageSource=[[GPUImagePicture alloc] initWithImage:copyImage];
copyGPUimage=[[GPUImagePicture alloc] initWithImage:copyImage];

invertFilter=[[GPUImageColorInvertFilter alloc]init];
     [ copyGPUimage addTarget:invertFilter];
[ copyGPUimage processImage];
[invertFilter useNextFrameForImageCapture];
 UIImage *imgTempr=[invertFilter imageFromCurrentFramebuffer];
 copyGPUimage= [[GPUImagePicture alloc]initWithImage:imgTempr];


gaussianBlur=[[GPUImageGaussianBlurFilter alloc]init];
[gaussianBlur setBlurRadiusInPixels:val];
[copyGPUimage addTarget:gaussianBlur];
[ copyGPUimage processImage];
[gaussianBlur useNextFrameForImageCapture];

UIImage *imgTempa=[gaussianBlur imageFromCurrentFramebuffer];
  copyGPUimage= [[GPUImagePicture alloc]initWithImage:imgTempa];

colorDodge = [[GPUImageColorDodgeBlendFilter alloc] init];

[stillImageSource addTarget:colorDodge];
[ copyGPUimage addTarget:colorDodge];
[stillImageSource processImage];
[ copyGPUimage processImage];
[colorDodge useNextFrameForImageCapture];
imageWithAppliedThreshold=[colorDodge imageFromCurrentFramebuffer];

//现在你已经得到了你的草图,你可以设置它的黑暗

 stillImageSource = [[GPUImagePicture alloc] initWithImage:imageWithAppliedThreshold];
monochromeFilter=[[GPUImageMonochromeFilter alloc]init];
[monochromeFilter setIntensity:intenVal];
[monochromeFilter setColorRed:0.0 green:0.0 blue:0.0];
[monochromeFilter setBackgroundColorRed:1.0 green:1.0 blue:1.0 alpha:1.0];
[stillImageSource addTarget: monochromeFilter];
 [stillImageSource processImage];
[monochromeFilter useNextFrameForImageCapture];
imageWithAppliedThreshold=[monochromeFilter imageFromCurrentFramebuffer];