"Close gap" in Fill tool

krita fill test jump gaps

Thanks for the feedback :slight_smile: I’m also quite astonished how well this works.
@Deif_Lou

  • There’s some heuristic that also fills areas that are not in the line of sight. So it also works with non-convex-shapes.

The detection of a lineart vs a background pixel is probably something the existing bucket fill already has a function that we can re-use.

It will get slower the larger the area (like regular bucket fill) and even slower, when filling non-convex-shapes.

Could you draw an example please?

2 Likes

Suppose you make the two lines as in your last video, with the gaps on the top side of each one, and then you want to fill the outside area by clicking on the bottom side of the image. How would that detect the gaps by just casting rays? Also, how do you close the gaps, just by drawing a line?

1 Like

Here’s an example:

  1. With gap detection set to a medium size tolerance (top example), it should fill the gaps that are below (or equal to) this tolerance, so the small and medium ones.

  2. With detection set to small (bottom example), all larger gaps remain open and only the smaller one is filled.

  3. And finally, with a large gap detection setting, the fill tool should only fill the left square.

The small detection is useful to only correct lines that failed to touch each other, whereas larger gaps remain open. You can see that having such a threshold will allow you to fill multiple regions at once depending on the threshold chosen. Thus saving a lot of time in the process as well. Ideally, the setting would be a pixel based input (integer), so you can set it to 20px, 51px or even 127px.

By the way, what are the plans for a gap detection in the colourise mask tool?

2 Likes

Good question. At the moment the heuristic works by restarting the raycasting recursively at the edges of the ā€œunexplored areasā€. So with many recursions, it can work around a circle from the outside. But the recursion depth could be a tool setting because it may starts filling too agressively.

image
It closes the gaps because the rays in the gap didn’t hit anything behind them. If there’s an object behind the gap, it will hit the wall behind it like in the next screenshot, but it will not leak out.

image

When the object is further away It will not try to leak out because it knows that the rays next to the gap are rather short and limit’s the raycasting distance.
image

7 Likes


What you’re describing is definitely possible. Since the algorithm ā€œknowsā€ all the gaps, it could measure the gap length and just behave as if the ā€œuser clicked in the gap againā€ if it has the desired length.

I don’t think raytracing is a good Idea for the colorize mask tool. The colorize tool already works well for gaps (at least for me) and has a more constant time behavior, the larger the image, the slower it is.

9 Likes

I was just questioning for the colourise mask, I have yet to test this feature myself, but could imagine it being applicable there too. That’s all :wink:

2 Likes

krita fill test megaeye

I wanted to give some development update:
In the video below the regular ā€œbucket fill toolā€ (like we have now in Krita) is used to fill Mega Man’s face and it leaks through the gap in the eye.
Then I use the new ā€œgap-awareā€-fill tool first to fill out the eye and then use the bucket fill as usual to fill the face.

(red lines appearing in the green area show the segmentation)

13 Likes

can we help you with something? like provide you with linearts to test?

These are really promising development.

2 Likes

agreed! it would be nice to see how it works with fuzzier or more textured lineart

2 Likes

I know Tahoma2D, an opensource animation software has option to close gaps (although I don’t remember if it can work in raster layers). Perhaps that would be of some use to develop it for Krita?

Also, is there someone doing nightly builds of Krita for Windows so I can test/try out any upcoming features that are in development (I don’t mind crashes, I save often)?

1 Like

@darkhog The nightly windows builds are here:
Krita_Nightly_Windows_Build [Jenkins]

I suggest that you get the portable .zip package. That will not affect your current installation and will use the same configuration settings and resources.

You can test it yourself. A windows .exe and the source can be found on my github here:

This is just a standalone test app, it will be integrated into Krita when the people decide that it works well enough.

It currently requires completely white backgrounds and .png images to work properly.

8 Likes

krita gap fill dev ranma

@ramskulls
Fuzzy and textured lineart is still on my to do list. For fuzzy line art, it should work with a threshold similar to the existing bucket fill tool.
This is actually quite simple to implement and we need that anyways if we want to fill anything with smoother lines than pixel art. At the moment, the test app only fills 100% white, as you can see on the two tiny spots on the shoulder where it isn’t completely white and didn’t get filled.

Now I would be really happy to get some feedback how well the ā€œfill-with-gapsā€ algorithm works :slightly_smiling_face:

7 Likes

Should we mark this feature request as #in-progress ?

3 Likes

I am curious about some places:

  1. Does it have adjustable parameters in the future?

  2. I noticed that it will divide the space of ā€œSā€ shape. Is there any space for optimization?

  3. When clicking different positions, the filling effect is different. Sometimes it can be filled at one time, but sometimes it needs to be filled multiple times, and it may leave a vacancy
    8
    8
    8

1 Like

@TheTwo
Thanks for testing the algorithm! :smiley:
1.) If you click on ā€œPreferencesā€ there’s some adjustable parameters. But I hope that we’ll able to minimize the number of adjustable parameters when this tool is available in Krita, because it might be too overwhelming for the average user.
2.) You can try to modify the parameters in the preferences and see if it gets better for you. There’s of course space for optimizations. But sometimes it could be better to let the user click 3 times than press undo 3 times because it filled too much.

3.) Yes, it always uses the position where you clicked to start it’s search for lineart. This is different from the implementation from GIMP where (according to the developer) it first analyses the whole image in a background process and then uses that information for the fill-with-gaps tool.

Oh, I didn’t see it! I’ll see it soon

At present, I don’t quite understand the parameters, but I think it is too complicated to fill in structures like hair. In addition, it is always ineffective for lines with large internal space.
image

@TheTwo
Thank you, both good and bad feedback are very much appreciated!

I took one of my lineart test pictures with hair and filled it with default parameters using my krita feature test app. It’s true that filling complicated structures like hair doesn’t work so well.
Below are the test results for both my testapp and GIMP’s lineart fill feature.
I fiddled around with GIMPs sliders for a few minutes, but the result was never what I expected. Maybe somebody mastered it already and can show that it works better than in my short video.

Krita Feature Testapp
krita test app fine hair

GIMP
gimp fill lineart

Update: I just tested GIMP’s tool with thick black lines and then it works very well but it also can only fill small areas at a time.

1 Like

Are there any ā€˜scientific’ papers on the subject in which researchers present a gap fill algorith? Maybe that could give you some additional clues. Don’t you think there will be bugreports submitted if the tool doesn’t fill the whole region (e.g. the hair) in one go? People are, by now accustomed to that from Photoshop and such. Blender and Illustrator do so too, but they just extend vector lines, which doesn’t seem feasible here. Unless you were to vectorise the outline of the isovist (raytracing) as bezier curves, perhaps?

1 Like

Yes, the filling effect of GIMP is not good, but mypaint is good.