Forum

(auto) filling a closed area in a texture

Hey,

does anyone have any ideas on how to fill an area surrounded by a closed line in a texture?

For example, imagine an all-white texture with a black line in it, like a circle. Suppose we want to ‘detect’ that circle, and fill the white area inside of the circle with another color. Ideally this should work automatically, but picking 1 pixel inside the area and starting to fill from there until a ‘very different color’ is found, would be great already.

Maybe the solution could be pixel-shader based (it doesn’t need to be efficient, because it should only be done once), but maybe there is another way.

Maybe even someone has already done something similar, and I just couldn’t find it on the forums? Don’t want to reinvent the wheel…

Thanks a lot.

would be cool to have that feature, but i don’t really know if that possible in ps, might be some two pass approach would work… but can’t herlp you much on code…

basically sounds like a flood fill. something like this should be rather easy to port if only we had nice texture input into dynamic nodes. it really depends on the performance one needs, but doing this in a pixelshader may be more complicated than it sounds at first…

if you have the xy data of the contour you can do it thru the new SVG nodes (polygon), then convert it to texture with the SVGTexturenode

think it would be slow

Being slow would not really be a problem.

@sapo: what do you mean by ‘if you have the xy data’?
I wanted some freely drawn form to be filled, so the edges should be detected. I don’t make assumptions on any specific form or size.

@ft: then i think it’s not suitable, i meant the spread of X and Y coordinates of the points of the line that you want to fill.
EG: the XY data coming from contour node.

if your still happy with a frame by frame feedback solution, this relatively simple shader will work:

fillshader.zip (5.8 kB)

awesome… no text …

oh thats a nice on. thx tonfilm,

there i stand corrected… :)

grande tonfilm.

a 3D version now please… I ve been tinkering about this for quite some time and I always have to switch to Blender s particle systems.
How to fill a mesh with a given number of equally distributed particles?
S.

@tonfilm: thanks, I will try that out somewhere in the next few days