Mask the model to change the background color

Very good results guys. Today I check the .xmp and so I get to learn how each of you have arrived at the solution. Thanks a lot g-man, Boris, Tim, Oscar, Steven and Todd. This is a great way to learn concrete things about darktable and thus better cope with the challenges that different images may have. And especially those of separating objects or people from a background.

1 Like

I included the develop settings (xmp) in the jpg metadata. In darktable, just load the jpg as the xmp sidecar. I’m not at the PC now, so I can’t generate until later.

I think it will be interesting to see how an AI tool handles this challenge (eg Lightroom).

1 Like

Yes, that would be great. I don’t use Windows or Mac neither Adobe but maybe some other user will test it in lightroom.

Thanks! I actually thought of doing that, but something made me think that jpg was a screenshot… don’t why I thought that. I just loaded it. Nice job!

I still have a few days left on my Lr trial - stay tuned! I’m far from proficient with Lr though, so not sure how it’ll go…

1 Like

But that’s the whole concept of ai. It doesn’t require skills. The algo does it for you and fast.

There is a silver of earring in her face, some strands of hair and some blueish light hitting the fingers that I think could make an AI mask hard to be perfect. That’s why I’m interested.

Ok, Lr.
On going to the masking tab, and selecting ‘people’ it thinks about it for a bit (20 sec maybe) then you see this:


then I click ‘Person 1’ and you get this, with the mask shown in a reddish overlay. It’s mostly pretty good, but there’s a wonky bit around the hands. Most of the other options work ok, but not the “hair” option.

Part 2 coming up…

1 Like

I know darktable lacks the possibility to use raster masks and I think it is technically impossible in the current development conditions (I’m not a technical guy), if someday the developers (who have done a fantastic job) manage to implement them in the mask selection system, with the use of picels, brushes and erasers to add or subtract parts to a selection, as GIMP and other programs do with quick masks, that would turn darktable into an exceptional tool, even more than it already is.

I clicked ‘create mask’, then found the ‘invert’ mask option, this got just the background selected. To make the masking clearer I just dropped the exposure on the masked area:


So it’s ‘ok’ but not ideal. In the screenshot you can see the add or subtract mask options… short of using a brush I don’t think I can improve on this one.
I found out how to color it like @g-man did…

and cloer up:

So my conclusion so far is that yes, it’s easy, I could do it with little knowledge of the software, and it looks, well, ‘good enough’ for some applications. But from this test, dt in the right hands, beats me with Lr hands down. I might try to research whther one can do better with Lr.

Humph… using ‘select subject’ instead of ‘people’ is better I think:



It does work - (SG mumbles grudgingly)
The hair is a bit odd though. Although I think many viewers (as opposed to the people working on it) wouldn’t notice.

1 Like

Glad to hear it. AI works as well but requires skils to fine tune the images. So we are on the right track with darktable. That’s one impression I got with that AI selection thing that still lacks precision and can mess up a selection. I’ve used image compositing programs for VFX like Nuke and it’s complicated the mask selection process even using green clipping backgrounds, because of the contamination of the figure with the background, especially the hairs. With work and by creating alpha channels you can achieve very good results. darktable uses very good selection methods with excellent results.

1 Like

ON1 works okay. Though I don’t use it much… I think its a bunch of edge aware stuff and not so much AI at least in the 2022 version I have…its a bit more advanced in the latest one… For ON1 you take a brush and draw strokes very roughly over areas to keep and areas to remove and then it calculates a mask. From there there is a refine brush and a chisel brush that you can use on the edges if you get halos. This does help when your run it over hair to clean it up…I think the brushes are refinements or versions of what they call the perfect brush which is an edge aware tool…if I get some time I will post an example for comparison but in this case for example @s7habo Boris’s mask was pretty good and funny enough even the blue channel alone did a lot of work but it really helped with the hair… in this case I am not sure the ON1 mask will be better but maybe faster?? The new version is more sophisticated than what I have…it also identifies items in the photo that you can automatically select as tags…

actually mask sharing between modules in DT works by sharing raster masks. So all you would need is loading external Alpha channel files as masks into darktable. I can not imagine that this would be really all that hard.

1 Like

Some tools as Exposure X7 have some sort of edge detection where user select areas to keep or ignore, a mix of draw masks and brushes to refine the selection, but I don’t think it is AI at all.

1 Like

One more quick go with Lr, as asked here: My first Play Raw - #25 by Colin_Adams


Not bad.

3 Likes

due to the quite homogeneous background that’s not a big job for AI. I doubt adobe would have released an AI function not able to cope with such simple jobs since separating subject and background is for sure a major task

There’s a bit of leakage of the background into the subject though.

1 Like

don’t expect magic from AI

I didn’t.
In fact, I didn’t expect it to work at all, seeing as presumably flying dragonflies were not included in the training set to any degree. Maybe it is just working by edge detection.
Anyway, it was much better than I expected.


GIMP - AI Remove image background (use rembg) => remove_background.py

1 Like

GIMP - AI Remove image background
GIMP - AI Remove image background (use rembg)

2 Likes