ios图像文本和颜色增强过滤器

时间:2017-08-23 09:16:52

标签: ios objective-c iphone image-processing uiimage

我正在尝试使用CIFilter和GPUImage滤镜在图像上应用各种效果(亮度,对比度,饱和度等),但是我会挣扎,需要像下面所示的增强效果:

增强前过滤器

Before Enhancement filter:

增强后过滤器

After Enhancement filter

我尝试过的CIFilter代码:

NSDictionary *options = @{ CIDetectorImageOrientation :
                               [[resultImage properties] valueForKey:kCGImagePropertyOrientation] };
NSArray *adjustments = [resultImage autoAdjustmentFiltersWithOptions:options];
for (CIFilter *filter in adjustments) {
    [filter setValue:resultImage forKey:kCIInputImageKey];
    resultImage = filter.outputImage;
}

GPUImage过滤器:

UIImage *inputImage = [UIImage imageNamed:@"Msource.png"];
GPUImageAdaptiveThresholdFilter *stillImageFilter = [[GPUImageAdaptiveThresholdFilter alloc] init];
stillImageFilter.blurRadiusInPixels = 10.0;// adjust this to tweak the blur radius of the filter, defaults to 4.0

UIImage *filteredImage = [stillImageFilter imageByFilteringImage:inputImage];

1 个答案:

答案 0 :(得分:2)

在这里输入代码//希望这有帮助,它在swift 3:

        var aCIImage = CIImage();
        var contrastFilter: CIFilter!;
        var brightnessFilter: CIFilter!;
        var gaussianBlurFilter: CIFilter!;
        var pointFilter: CIFilter!;
        var vignettFilter : CIFilter!;
        var context = CIContext();
        var outputImage = CIImage();
        var newUIImage = UIImage();
        var finalImage = UIImage()

       DispatchQueue.main.async
                        {
                            self.gaussianBlurFilter = CIFilter(name: "CIExposureAdjust");
                            self.gaussianBlurFilter.setValue(self.aCIImage, forKey: "inputImage")

                            self.gaussianBlurFilter.setValue(NSNumber(value: sender.value), forKey: "inputEV");

                            self.outputImage = self.gaussianBlurFilter.outputImage!;

                            let imageRef = self.context.createCGImage(self.outputImage, from: self.outputImage.extent)

                            self.newUIImage = UIImage(cgImage: imageRef!)
                            self.testView?.image = self.newUIImage;
                    }


 // 

Dark Image with text and having no filters applied to it

https://i.stack.imgur.com/s1STp.png

Same Image with text and having CIExposureAdjust Filter applied to it

https://i.stack.imgur.com/uU0Oz.png

链接:用于演示项目。

https://drive.google.com/open?id=0B-EIC_4IXtA9UjFwT3o0dXI1OTA