"Close gap" in Fill tool

Well, I have to say that I want to implement gap closing. I also know about what you said.

The most basic form of gap closing, given a mask where white means selected pixels (pixels to be filled), is by opening the mask (erosion followed by dilation. In krita think of shrink selection followed by grow selection). If the black values where the selected ones then it would be closing, as you said.
That approach is straightforward but one issue with it is that the mask can end up with some regions chopped off that should’t be eliminated:


In the image one can see that opening does a good job dividing the region in smaller ones given a gap size, but it also removes other small features. One can argue those are gaps since they have a size less than the selected gap size, but I think that only the removed regions that join two or more big non-removed regions should be considered gaps.
So, some reconstruction should be performed on the selected big region. I thought of performing some labeling and mark the removed regions as gap or non-gap depending on the number of big selected regions they touch. But that is not particularly fast.

Another issue is that this approach is kind of global. It requires to compute first the whole region and then segment it and choose some sub-region. That can lead to taking big time to select the whole region, even if the resulting sub-region is small. That surely would confuse the user. I think csp (I’m just guessing this given the speed of its filling) does it kind of on the fly. It’s like it checks for gaps as it fills. Although I didn’t find a fast way of doing this yet. And csp’s gap closing is not perfect also, but maybe that is part of the compromise between quality/speed.

8 Likes