1
我已經使用GPUImage框架實現了鉛筆素描濾鏡。但是我認爲這個過濾器對於生成輸出來說太複雜了。GPUImage鉛筆素描濾鏡優化
鉛筆濾鏡功能
- (void)pencilSketch
{
//UIImage *inputImage = [UIImage imageNamed:@"portrait.jpg"];
UIImage *inputImage = [UIImage imageNamed:@"selfie4.jpg"];
GPUImageGrayscaleFilter *grayFilter = [[GPUImageGrayscaleFilter alloc] init];
GPUImageColorInvertFilter *edgeFilter = [[GPUImageColorInvertFilter alloc] init];
GPUImageGaussianBlurFilter *blurr = [[GPUImageGaussianBlurFilter alloc] init];
blurr.blurRadiusInPixels = 8.0; // Edge Sensitivity
blurr.texelSpacingMultiplier = 8.0; // Edge Strength
GPUImageLinearBurnBlendFilter *filter = [[GPUImageLinearBurnBlendFilter alloc] init];
UIImage *invImg = [edgeFilter imageByFilteringImage: inputImage]; // Color Invert
UIImage *blurrImg = [blurr imageByFilteringImage: inputImage]; // Gaussian Blurr
// Linear Burn Blend
GPUImagePicture *mainPicture = [[GPUImagePicture alloc] initWithImage: invImg];
GPUImagePicture *topPicture = [[GPUImagePicture alloc] initWithImage: blurrImg];
[mainPicture addTarget: filter];
[topPicture addTarget: filter];
[filter useNextFrameForImageCapture];
[mainPicture processImage];
[topPicture processImage];
UIImage *resultedimage = [filter imageFromCurrentFramebuffer];
resultedimage = [UIImage imageWithCGImage:[resultedimage CGImage] scale:1.0 orientation: invImg.imageOrientation];
GPUImageColorInvertFilter *bf = [[GPUImageColorInvertFilter alloc] init];
resultedimage = [bf imageByFilteringImage: resultedimage]; // Color Invert
resultedimage = [grayFilter imageByFilteringImage: resultedimage]; // Gray scale
UIImage *grainImage = [UIImage imageNamed:@"stroke2.jpg"];
GPUImageGaussianBlurFilter *gBlurr = [[GPUImageGaussianBlurFilter alloc] init];
gBlurr.blurRadiusInPixels = 5.0;
UIImage *blurrGrainImg = [gBlurr imageByFilteringImage: grainImage];
GPUImagePicture *blurrPic = [[GPUImagePicture alloc] initWithImage: resultedimage];
GPUImagePicture *topPic = [[GPUImagePicture alloc] initWithImage: blurrGrainImg];
GPUImageSoftLightBlendFilter *maskedFilter = [[GPUImageSoftLightBlendFilter alloc] init];
[blurrPic addTarget: maskedFilter];
[topPic addTarget: maskedFilter];
[maskedFilter useNextFrameForImageCapture];
[blurrPic processImage];
[topPic processImage];
resultedimage = [maskedFilter imageFromCurrentFramebuffer];
resultedimage = [UIImage imageWithCGImage:[resultedimage CGImage] scale:1.0 orientation: inputImage.imageOrientation];
GPUImageColorBurnFilter *bFilter = [[GPUImageColorBurnFilter alloc] init];
bFilter.brightness = 5.0; // Edge Darkness
resultedimage = [bFilter imageByFilteringImage: resultedimage];
baseImage.image = resultedimage;
}
輸出圖像的過濾器
請任何人建議我如何優化該過濾器的結果呢? 我想如果有人指導我爲此編寫着色器程序。我可以製作一個自定義的GPUImageFilter,併爲其編寫着色器程序。