Bug 455919 - Enclose and Fill "Include Surrounding Area" option unintuitive.
Summary: Enclose and Fill "Include Surrounding Area" option unintuitive.
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Tools (show other bugs)
Version: 5.1.0-beta1
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords: release_blocker
Depends on:
Blocks:
 
Reported: 2022-06-25 14:13 UTC by wolthera
Modified: 2022-07-12 13:29 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Image showing the problem, see summary. (142.83 KB, image/png)
2022-06-25 14:13 UTC, wolthera
Details
Tool options, strawberry layer was labeled red, for the record. (38.85 KB, image/png)
2022-06-25 14:14 UTC, wolthera
Details
include contour regions example (506.90 KB, image/png)
2022-06-26 13:55 UTC, Deif Lou
Details
include surrounding regions example (26.05 KB, image/png)
2022-06-26 14:33 UTC, Deif Lou
Details

Note You need to log in before you can comment on or make changes to this bug.
Description wolthera 2022-06-25 14:13:17 UTC
Created attachment 150147 [details]
Image showing the problem, see summary.

In the enclose and fill tool, setting the options to 'Regions Surrounded by', and then toggling 'Include surrounding regions' gives unexpected results.

In the attachment, there's a sequence of 4 images:
0. The default image, a set of strawberries drawn with red, with the 'seeds' erased and some simple leafs drawn on top.
1. The enclosing area.
2. Results from 'regions surrounded by transparent', the lower strawberry is filled with blue as expected.
3. Results from 'regions surrounded by transparent' + 'Include surrounding regions' , for some reason, only the transparent 'seeds' on the upper starberry are filled.

"include" suggests to me that 2 and 3 would be combined, but that is not happening for some reason?
Comment 1 wolthera 2022-06-25 14:14:06 UTC
Created attachment 150148 [details]
Tool options, strawberry layer was labeled red, for the record.

Attaching the tooloptions for '3.'
Comment 2 Deif Lou 2022-06-26 09:08:12 UTC
Hi. Yes, this case is a bit tricky. Even today I have a hard time reasoning about what should happen and honestly I don't know if that option would be that useful.

I'll try to explain what I did and see if we should change how it behaves or if we can make it clearer.

* In the case where the surrounding regions are not included, all the regions inside the enclosing area that are surrounded by the chosen color and that do not touch the contour of the enclosing area, are selected.
* Then I thought that maybe allowing to keep also the color that surrounds would be useful. For example, if you have some regions delimited by a colored line, like they do in anime, say highlights "blobs" closed by a colored line, and you want to fill both the interior of the "blob" and the contour as well. (Most of the time this could be achieved with other modes, that's why I doubt now this option is that useful. I would not implement it if I were to code this now. Only if it was requested).
* The algorithm is straightforward:
    * First we select all the regions, from the contour of the enclosing area, no matter the color, until the surrounding color is reached.
    * So what remains not selected are regions of the surrounding color and whatever they have inside if they form closed loops. So we invert the selection to have those selected.
    * Then, if we should not keep the surrounding regions, we just remove those from the selection.
    * Finally we remove any remaining regions that touches the enclosing area contour, so that what is selected is entirely inside.
* So, in the case of the strawberries, when "include surrounding regions" is not selected:
    * Everything from the contour is selected until transparent is reached. This selects the portions of the top-right strawberry that touch the contour.
    * That selection is inverted, so we have now all the transparent regions plus the bottom-left strawberry selected.
    * Then we remove the transparent regions, and we are left only with the pink regions of the bottom-left strawberry.
* When "include surrounding regions" is selected it is more tricky:
    * Everything from the contour is selected until transparent is reached. This selects the portions of the top-right strawberry that touch the contour.
    * That selection is inverted, so we have now all the transparent regions plus the bottom-left strawberry selected.
Comment 3 Deif Lou 2022-06-26 09:23:21 UTC
Sorry, I hit return accidentally and that got posted. I was saying:

* When "include surrounding regions" is selected it is more tricky:
    * Everything from the contour is selected until transparent is reached. This selects the portions of the top-right strawberry that touch the contour.
    * That selection is inverted, so we have now all the transparent regions plus the bottom-left strawberry selected.
    * Here is the tricky part: the surrounding regions should be kept, but also the regions that touch the  surrounding region should be removed. So what is happening in the strawberries image is that the transparent areas are not removed from the selection, but then the areas of the selection that touch the contour are. So, when we arrive at this step we have 2 independent regions in the selection: one is the bottom-left strawberry and the transparent area that surrounds that; and the second are the transparent blobs inside the top-right strawberry. The first one touches the contour. The second one does not. So, since the regions that touch the contour are removed, only the the transparent blobs inside the top-right strawberry remain selected.

As you can see it's kind of difficult to reason about this mode whit "include surrounding regions" option. I think it should be removed. I also think CSP does not have that option.
Comment 4 wolthera 2022-06-26 10:57:29 UTC
Yes, it might be better to turn it off in these cases.

What gets me though is that, why, if the option "removes" candidate areas when they touch, is the option called "include"?

Similarly, do you have a sample case where it works? Because that was kinda my problem: I couldn't figure out how to use it at all.

I'm marking this as a release blocker because we need to make a decision on what to do with this.
Comment 5 Deif Lou 2022-06-26 13:15:15 UTC
Well, that last comment just shows that the options are not clear enough. The "include surrounding regions" is different from the "include contour regions". I'll try to explain what kind of concepts one needs to have into account:
* The enclosing region is the region the user makes to limit what shapes should be considered.
* The contour of the enclosing region is just that, the limit between inside and outside of the enclosing region.
* The closed, enclosed, regions, are those regions that can be delimited inside the enclosing region and that lie entirely inside that, that is, those that are selected and that do not touch the enclosing region contour.
* "Include contour regions" refers to regions that can be selected given the options when using the "regions of specific color/transparent" or "all regions except specific color/transparent", but that touch the enclosing contour. By default those should not be selected, since they are not closed (since they touch the enclosing contour, part of them lie outside the enclosing region). The only reason I can remember I included this option was this: Imagine you have a colored lineart (say black) on a transparent layer. For example a character head with different areas such as face, hair, lips, etc.. Then, if you want to color the lines themselves instead of the inner regions, with different color that match the filling colors (a darker shade of skin tone for the lines of the face, or a darker tone for the hair lines, for example) you can just lock the alpha on the layer and then select and fill (or just use the shape brush) whatever portion of the line art you want filled. But if the "non-lineart" areas are not transparent (for example they are white or have already being filled with other colors) you can not rely on the "lock alpha" feature. And this is when the "include contour regions" can be useful. Basically, with that option selected, all the enclosed regions of the specific color will be filled, regardless of if they touch the enclosing contour or not. This alone is a very niche use case, since I think the better and less issue-prone approach would be to have the lineart on its own transparent layer.
* When I refer to the surrounding regions, I mean those regions of the user-given color in the "regions surrounded by x" methods. Those can touch the enclosing contour or not. Imagine a set of white blobs with a black outline on a transparent layer, for example. You can select regions surrounded by black so the white part should be filled, and the black regions should remain black. If "include surrounding regions" is selected then the white interior and the black surrounding should be selected. But as I said, now I think that if "include surrounding regions" is selected, the same result in the 90%+ of the cases can be achieved by other modes, like "select all regions". I said 90%+ and not 100% just because I myself am not totally sure. It would need some exploration by the users.
* If "include surrounding regions" is on, then the selected regions should be composed by all the closed regions that are totally inside of a region of the specified color, plus the surrounding region of the specified color itself. But if one of those composed regions touches the contour it is removed (only the resulting regions that lie totally inside the enclosing region are selected).

Again, I think the "include surrounding regions" option can be removed (at least from the interface), and we'll see if there is requested in the future.
The  "include contour regions" I find more useful and easy to understand. But since maybe it won't be needed in the majority of the cases, I don't know if it should be also removed/hidden.
Comment 6 Deif Lou 2022-06-26 13:55:11 UTC
Created attachment 150160 [details]
include contour regions example

In the example can be seen the usage of the "include contour regions" option in the "select regions of specific color/transparent" mode. The image was already colored and has no alpha, and I want to fill the lines of the nose. For that I chose "regions of a specific color" and the color of the lines. If "include contour regions" is not selected, then only those lines that are entirely inside the enclosing region are filled. But in this case I also want to fill the lines of the nose that touch the lines of the eyebrows. I can not select the eyebrows since I want those lines to be colored with another color. so the only solution is to use the "include contour regions", which will fill every region of the given color, even if it touches the enclosing contour.
Comment 7 Deif Lou 2022-06-26 14:33:01 UTC
Created attachment 150161 [details]
include surrounding regions example

In this image, the second and third figures are filled using the "select regions surrounded by specific color" with black as surrounding color, the second one with the option "include surrounding regions" off and the third with it on. It can be seen that the "include surrounding regions" just treats the chosen surrounding color as part what should be selected. In the second figure only the regions that are entirely surrounded by the chosen surrounding color and that do not touch the enclosing contour are selected. In the third figure, both the regions that are entirely surrounded by the chosen surrounding color and the regions with the surrounding color are selected, as long as those don't touch the enclosing contour. So in the ellipse at the right and the one at the center-bottom, some black blobs are selected since the surrounding color is considered part of what should be selected, and they do not touch the  enclosing contour. A similar effect can be achieved using the "select all regions" mode (figure 4). Not exactly the same, but this is a made up example. I think that in practice very few people would want to fill like it is shown in figure 3.
Comment 8 Dmitry Kazakov 2022-07-12 13:29:35 UTC
The bug is closed by this commit: https://invent.kde.org/graphics/krita/-/commit/510955dcf6b0445fb0843fd60411c70dc66c22ba