Search code examples
image-processingcomputer-visiongpuimage

Is there a way to flood fill using GPUImage?


I am using a GPUImage edge detector to create edge boundaries for text. I then want to convert those text elements to solids rather than outlines. The first what I can think of doing that is to flood fill the region. Is there a way to flood-fill using GPUImage, or perhaps a better way to achieve the result I want?


Solution

  • GPUImage is based around the application of vertex and fragment shaders to input image data. Unfortunately, standard flood fill algorithms aren't a great fit for these shaders.

    Flood fills generally are calculated in a way that results from one pixel depend on results from another. This makes them difficult to calculate in a parallel manner within a fragment shader. Maybe you could rig up something for an iterative calculation, but this might be an operation that's best handled on the CPU side.

    Beyond that, if your goal is to highlight text and hide the rest, there might be other ways of achieving this. I've seen adaptive thresholds (which threshold based on a box blur of a large area of surrounding pixels) do this, and you might be able to help that by running a bilateral blur beforehand (bilateral blur can blur images while preserving sharp edges, enhancing those edges as boundaries).

    Depending on your specific needs, this might be a broader language-independent image processing question that the folks over at Signal Processing may be able to help with.