0

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.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Tony
  • 373
  • 5
  • 18

2 Answers2

1

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

Garrett Albright
  • 2,844
  • 3
  • 26
  • 45
0

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.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • Thanks @Brad. I'm not too concerned with the speed - although clearly faster is better. My aim is essentially to render a photo as a line drawing - as a precursor to physically painting the image on canvas. I did try one of the threshold edge detection filters but there seemed to be a lot of extra noise however I tinkered with it. I've not customized filters, but will give your idea a shot. Thanks! – Tony Feb 19 '13 at 02:23
  • @Tony - For a photo, your largest concern will probably be memory usage, so anything that requires a large number of render passes could be troublesome. You might be able to clean up some of the noise from thresholded edge detection using an opening filter (or closing, I get those two mixed up sometimes) with a smaller radius. – Brad Larson Feb 19 '13 at 16:18
  • @BradLarson is it possible to apply threshold edge detection filter to videoCam,but instead of black and white i should be able specify my own RGB to edges and background? – Yadnesh Dec 29 '13 at 12:05