Dilating flood-fill [WIP]

Hi all, I’ve created “dilating flood-fill” and I would like to pull-request it later.
That branch “fill_dilate” is here,

This feature does simple dilation, to fill spaces between contour and flood-filled area.

without this feature:

with this feature:

But, before doing pull-request, I am worried about the text of the label and tooltip of Options Presenter makes sense properly as English.

In Krita, it is shown as “Grow Selection:”.
But, there is no selection in mypaint, and my code does not use selection.
so I use “Dilation Size”.
And, the tooltip text is “How many pixels the filled area to be dilated.”

Are they make sense in English? are there any better, plain text?


By the way, For your reference…
I also created another branch.but it is just experimental one…
Previously I planned to pull-request this if this branch work well, but it does not work well.
So I gave up it.:disappointed_relieved:
that branch “gapclose_fill” is here

It does “psuedo gap-closing flood-fill”, in addition to “dilating flood-fill”.

“psuedo” means, actually this function does nothing somewhat special vector-based gap-detecting or fantastic mathematical operations like ClipStudio or Lazybrush one.
This is simply, just dilate contour to close gap.

And after that, search clear space to flood-fill.
then, dilate the flood-filled area.

for example, there is such dashed line art… I clicked the center of that area…


flood-fill with psuedo-gap-closing feature do this:

But, It is only useful for convex area, actually rather useless…
When gap-close-flood-fill with star like shaped area, the tip part remains unpainted.

because it cannot distinguish narrowing contour and opened gap.

Using a smaller value for ‘Gap Closing Radius’ and use in conjection with dilation
might make it a bit better.

but there is still empty area.
So I think that this code is only useful under very limited circumstances.

I’m very weak for math, Once I have read bucket tool : Auto close gap feature · Issue #296 · mypaint/mypaint · GitHub ,
and that Lazybrush pdf document, I cannot understand almost everything…
I hope someone will implement that Lazybrush like fill feature in future!:smile:

Since I came up with an easy idea, I tried implementing it immediately.
That is, rather brute-force way, detect all fillable points which is adjoining gap-closing-flood-filled area, and do flood-fill each of them.
If flood-fill spilled out, use that result as a part of unfilleable area.
otherwise, merge it to final flood-fill tiles.

For example , When there is a star-shaped area with small opened gap…


It is filled up now.


It looks like work well, (at least for me :smile: )

But there is still problem…
Another example, If the opened gap is actually surrouded by large far contour,


It is not filled. This is good.


But when that contour is more close…


It is filled up too!!


Because, this functionality uses ‘spilled_out’ flag, that is returned from new flood-fill function “flood_fill_empty_tip”, which is specialized for filling unfilled small tips.

That function returns spilled_out state when the flood-fill reached each of tile border.
So, large far contour is actually not visible from flood_fill_empty_tip.
But, close contour is within valid tiles, so it is filled up.

I have no idea to avoid it…:cry:

But, it might be no problem in real usage case. :smiley:
I’ll test this flood-fill by myself painting work later.
(or… another huge problem might be found…)

1 Like

Recently I learned that the LazyBrush uses ‘Graphcut’, and Opencv2 has already simuliar function ‘grabCut’, so I’ve tested that function for mypaint.

grabCut function seems to be for photographic image, but when we feed enough foreground hint pixels into that function, we can use it for manga/anime style linarts, the result is not so bad.

sample movie is here: (volume warning: this clip contains background music)

I think this might be useful…?:smiley:

but there is some problems around user interface, and whether Opencv2 library can be used with mypaint.

4 Likes

That’s really neat! Filling in flats is one of the most boring tasks in making an image.

1 Like

How can I add this to myPaint? Also is it difficult to add it?

It’s a bit involved since you have to build and install his fork of MyPaint from Source. So you have to be comfortable with using the terminal, or cmd prompt and using git. Plus it also depends what operating system you are running.

In addition to @odysseywestra … if @Spasmodic76 meant to add ‘grabcut fill’, not meant ‘dilating fill’, you need to install OpenCV2 python binding library, in addition to Mypaint build libraries.
Installing that library into Ubuntu(or some debian forks), it is very easy, just do ‘apt-get install python-opencv’.
(Although older Ubuntu package of python-opencv might not be OpenCV2, might be older OpenCV binding. I’m using Ubuntu 16.04.)

But I don’t know how to install (and how easy/difficult to do) it into Microsoft Windows environment…
MacOS have some packaging system such as ‘brew’ or ‘Macports’,so it might be easy too.

For your convenience, ‘grabcut fill’ use opencv2 only from python codes.
C++ modules for ‘grabcut fill’ does not call opencv2 functions, it just call numpy C++ library which is included already to Mypaint build environment.
So C++ development files of OpenCV2 library would not be needed.

1 Like

Hey thanks, I installed the python libraries. I hope that this feature can be added to the repositories soon.

these fill approaches are all a huge improvement over what’s in mypaint atm and I really hope they get merged into trunk.
The dilating fill slider feature is a must have imo.
The gap closing as well.

On the star example - some software such as clip paint has solved this by introducing another tool that lasso select fills small closed areas with color like this:

It’s called ‘close and fill’

They also have another lasso-styled tool that is very useful for cell shading - its called lasso-fill:

The grabcut fill approach reminds me of lazybrush and its colorize implementation in gmic:

If you are thinking of how to do it as a gui - it’s worth looking into krita, as the devs there are already working on a standalone tool and mask type for it. Their approach is similar to what Tvpaint did in the new version to integrate it better.
They call it ‘CTG layer’

Hope these links are useful. Thank you for the hard work. Please keep going! I hope to see these merged to trunk! :smiley:

1 Like

Hi, @blurymind, It is very impressive & useful information!
I didn’t know about ‘Close and fill’ , ‘Lasso fill’ and ‘CTG LAYER’, these interfaces look very intuitive and easy to use.
I think that I will make it with reference to them, especially ‘Close and fill’.:blush:
Thanks!!

1 Like

@dothiko Thank you for working on this. I think its currently mypaint’s weakest point. The bucket tool has a lot be desired

In regards of having a lasso type tool in mypaint for filling - it would be very good, but will take more work. Mypaint doesn’t even have a lasso selection atm - so someone will need to write an entirely new class.

The close and fill tool can be combined with a standard bucket tool as it is very very good at quickly cleaning little corner areas that the bucket fill couldnt get.But it could also easily replace the bucket tool altogether. :smiley:

Note how ‘close and fill’ also fills in closed alpha areas inside the lasso area - specifying that area is it’s biggest advantage over the bucket tool, which would always operate on the entire canvas as area and will often spill

The ‘‘lasso fill’’ tool is very similar- but it seems to also fill areas that already have color - that makes it ideal for cell shading!

One last note to make is how all the bucket tools that clip paint has are all grouped under the bucket tool- they are simply modes of the same tool. I think mypaint should adopt this approach in order to avoid clutter. It would be worth having all of these bucket approaches - as each has strong and weak points depending on where they are used

Here is a longer video of the process in clip paint
https://twitter.com/OhHeyDJ/status/879544241361362945

Recently Gmic dev added a new filter that automatically cleans up a drawing like this:
e38722cf8d5ed647bdcdb61fd47755bb21357fa3_1_690x302

Its open source, it could help you?
You will also find gmic’s implementation of the lazybrush approach there

1 Like

Hi, @blurymind, Thank you for your opinion!

I agree with you, ‘specifying area’ would be very helpful when flood-fill spilled out. :blush:

If ‘Close and fill’ / ‘Lasso fill’ are too difficult to implement against my expectations, I think at least ‘spcifying area’ functionality should be added to standard bucket flood-fill tool.

By the way, G’MIC is very interesting, but it is so difficult & complicated even source code produced, I think that I can not handle it…:sob:

What you’re doing is somewhat similar to G’MIC’s ‘Colorize Lineart[smart coloring]’, although said plugin doesn’t allow you to choose the colors and will just fill your lineart with random stuff instead.

Hi @MR4Y, Does the ‘said plugin’ mean about ‘grabcut fill’?

Surely, cv2.grabcut would be almost same algorithm(Graphcut) as ‘Colorize Lineart’ of G’MIC.
The difference is, G’MIC can accept multiple color sample pixels in the source layer at once.

On the other hand, current implementation of ‘grabcut fill’ only accepts the ‘current brush color’ pixels in source layer.
All other colors in the layer are just treated as ‘background marker’, not used actual fill.
It is something like ‘fill-guard’.
This come from that cv2.grabcut recognizes only binary image, just foreground and background.
(Although, calling cv2.grabcut multiple times might solve this problem…)

Anyway, so you might need to select the brush color (again) before execute grabcut-fill.

But this interface might be hard to use/understand. Actually, I also mistake the color designation often.:disappointed_relieved:
So I have been searching for a better one.
I think that the ‘Close and fill’ interface can also be applied to grabcut fill.:blush:

@dothiko Yes and no.

Hi @MR4Y, I’m sorry I had overlooked ‘smart coloring’… and I didn’t know about that great new feature.
Thank you for letting me know about it.:blush:
When I said about G’MIC Colorize, I kept the “Colorize ‘comics’” in mind.

http://timotheegiet.com/blog/comics/gmic-colorize-comics-working-in-krita.html