Tony
Tony

Reputation: 373

GPUImage CannyEdgeDetectionFilter with white edges?

I'm using GPUImage from the Git repository to apply some filters to images. I notice that the edge detection filters (I'm using the CannyEdgeDetectionFilter specifically) paint white edges on black background. Anyone know how to make that black edges on white background - or another filter that would do it (and not be heavyweight since that's the only filter I would need from that library).

Thanks Tony.

Upvotes: 0

Views: 2205

Answers (2)

Brad Larson
Brad Larson

Reputation: 170317

As Garrett suggests, you could simply invert the colors of that filter to get the result you want. However, that will introduce another filter into the chain and could slow things down.

You can get the inverse of the Sobel edge detection filter using GPUImageSketchFilter. The only difference between the two filters there is the second-to-last line of the fragment shader, where the color returned is 1.0 minus the edge intensity, instead of just the edge intensity.

The same thing can be done here for the Canny edge detection, only you'll need to replace the GPUImageWeakPixelInclusionFilter with one that has the following for the last line in its shader:

 gl_FragColor = vec4(vec3(1.0 - sumTest * pixelTest), 1.0);

You can copy and paste all of the rest of the code for this filter, along with all of the code for the Canny edge detection filter, then just change the Canny filter to use your custom filter class instead of GPUImageWeakPixelInclusionFilter and give your custom Canny edge detector your own name.

One warning about using the Canny edge detection filter: it does the whole four-step Canny process, so it is a lot slower than the Sobel edge detection filters uses a lot more memory. You can get a reasonable approximation of the Canny results at a lot lower cost using one of the thresholded edge detection filters.

Upvotes: 0

Garrett Albright
Garrett Albright

Reputation: 2841

GPUImageColorInvertFilter is available with GPUImage and should do what you need.

Upvotes: 1

Related Questions