some_id
some_id

Reputation: 29896

Multiple Filters using GPUImage Library

I am trying to apply 3 filters to an image.

One rgbFilter which is has its values constant, a brightness filter and a saturation filter, both of which should be able to be modified and the image should update.

I have followed the advice here.

I have setup a UIView using IB and set its class to GPUImageView. For some reason the image doesnt show.

My steps are as follows:

self.gpuImagePicture = [[GPUImagePicture alloc] initWithImage:image];
[self.gpuImagePicture addTarget:self.brightnessFilter];
[self.brightnessFilter addTarget:self.contrastFilter];
[self.contrastFilter addTarget:self.imageView];

and then I call this which sets the constant values on the rgb filter

[self setRGBFilterValues]

I setup my filters before this using:

- (void) setupFilters
{
    self.brightnessFilter = [[GPUImageBrightnessFilter alloc] init];
    self.contrastFilter = [[GPUImageContrastFilter alloc] init];
    self.rgbFilter = [[GPUImageRGBFilter alloc] init];
}

Am I missing a step or why is the image just displaying nothing?

Upvotes: 0

Views: 3398

Answers (2)

pejalo
pejalo

Reputation: 981

For my first time using this GPUImage library, it took me way too long to figure out how to simply apply multiple filters to a single image. The link provided by the OP does help explain why the API is relatively complex (one reason: you must specify the order in which the filters are applied).

For future reference, here's my code to apply two filters:

UIImage *initialImage = ...
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:initialImage];

GPUImageSaturationFilter *saturationFilter = [[GPUImageSaturationFilter alloc] init];
saturationFilter.saturation = 0.5;
[stillImageSource addTarget:saturationFilter];

GPUImageGaussianBlurFilter *blurFilter = [[GPUImageGaussianBlurFilter alloc] init];
blurFilter.blurRadiusInPixels = 10;
[saturationFilter addTarget:blurFilter];

GPUImageFilter *lastFilter = blurFilter;
[lastFilter useNextFrameForImageCapture];
[stillImageSource processImage];
UIImage *processedImage = [lastFilter imageFromCurrentFramebuffer];

Upvotes: 1

Brad Larson
Brad Larson

Reputation: 170319

You're missing one step. You need to call -processImage on your GPUImagePicture instance to get it to propagate through the filter chain.

You also need to call this anytime you change values within your filter chain and wish to update the final output.

Upvotes: 5

Related Questions