Mask the model to change the background color

Hello everyone.

This is not remotely a good image, I only use it as study material, in this case I want to separate the model from the background, this is a “simple image”, in other programs like GIMP it is quite easier to do this task, using a mask. In this image, despite being a single color background, as there are variations in the background fabric, lighting, etc I find it a bit difficult (without leaving darktable to another application) to make this selection using the luminosity mask options.

1- I would like to see how users assume a type of selection with these characteristics (.xmp).
2 - Change the background coloring.
3 - How long did it take them to make this type of selection?

I have failed miserably trying to make this selection and I would like to learn.

I’m using darktable 4.3.0~git245.bf38c1a9-8918.1

_DSF9520.RAF (47.8 MB)
This file is licensed Creative Commons, By-Attribution, Share-Alike.

_DSF9520_03.RAF.xmp (11.0 KB)

This was my try

This is other image, but in that case I changed the dress color, selecting and changing dress colors was easier.

Greetings from La Habana, Cuba.


My approach would be to take another image with better lighting/background. :slight_smile:

But to practice with your image, I would start with Drawn & Parametric and select Hue Channel (Hz) first. Using the color area picker I select the color area I would use. In this case it was the right side. Tweak the detail and mask contrast, and that’s normally enough for me on most images. But this one was still picking up the hair, so I then used the chroma channel to not pick that up. Lastly I used the drawn area in reverse polarity around her to avoid the shirt being part of the mask.


One of my earlier issues was drawing the mask first instead of using the channels. I ended up with some sharp edges at the drawing areas. Now I default to do the drawing at the end and it seems to give me better results.


Yes I had to make that later :wink: But this background was particularly interesting as exercise to practice the masks.
Thanks a lot fot your tips!!

Any chance of an xmp? :slightly_smiling_face: I tried to follow your instructions, but it didn’t come out very well…

I don’t know how others would do it. But I think in this case, with the white blouse, which absorbs some of the background color, it might be good to have part of the mask capture those tones as well. The white gets contaminated by the background color and it’s partly good to change the background color, otherwise it would look strange to crop (I think).

Ps. Sorry for my No English I’m not a native speaker.

@g-man has described the good way. Does this result meet your needs?

The result:

_DSF9520.RAF.xmp (12,1 KB)

I have exaggerated the colours a little to make the difference clear.

This would be a good topic for a new episode. :slight_smile:


Perfect!! I’ll check the .xmp at the morning. Thanks a lot.

I’ll wait for the new episode then :blush::wink::+1:

1 Like

Very nice the blue channel there really does nice work…

1 Like

Nice challenge, thanks for something unique!

mask-the-model_DSF9520.RAF.xmp (22.6 KB)
dt 4.2

Used parametric masks for the background and shape mask for the shirt.


I have made a new instance in divide mode and it has given me good results.

Captura de pantalla de 2023-01-18 10-09-24.png

_DSF9520_01.RAF.xmp (13.1 KB)


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