Cynichniy Bandera
Cynichniy Bandera

Reputation: 6103

How to use GPUImageConvolution3x3 for kernels bigger than 3x3?

Brad Larson,

First of all, thank you a lot for your tremendous work with GPUImage, started using and it looks pretty solid and useful.

My question is, how to use GPUImage convolution 3x3 for bigger kernels. I had impression that any convolution may be expressed through kernel 3x3 but how to implement it? I specifically mean gabor kernel. Was going to try it with convolution rather than creating new class of filter.

Thanks.

Upvotes: 0

Views: 156

Answers (1)

Brad Larson
Brad Larson

Reputation: 170319

For a larger convolution (5x5, etc.), you'd need to create a new filter type that performs that convolution. The basic 3x3 convolution is provided in the framework because it's fast and easy to specify. You also get the nine texture reads almost for free on most iOS devices.

When you start going beyond that, things get a lot more expensive. A 5x5 convolution requires 25 texture reads, and so on. This can lead to really slow processing.

As a result, operations like a Gaussian blur are done in the framework by using a separable kernel. First, the image is blurred horizontally, then the blurred horizontal result is blurred vertically. This dramatically reduces the number of texture reads and calculations.

I believe the Gabor filter can be represented by a separable kernel (or series of separable kernels), like is attempted here. You could translate the work there into a fragment shader with a given radius to implement your Gabor filter in a more efficient manner than just a large-area convolution.

Upvotes: 2

Related Questions