[AI] AI object mask tool#20378
Conversation
|
Thanks for this new implementation. I'll test soon. |
|
@andriiryzhkov : I have created the |
|
@TurboGit I will create a PR with models that are ready, because I have some models just for next experiments. I will keep them separate. |
|
Sounds good to me. |
|
@TurboGit can you initialize repository |
|
After testing, I can confirm SegNext runs a little bit slower than SAM2.1, though I was able to optimize model loading and inference to make it reasonable. Mask quality is lower than SAM2.1. I had to tweak mask post-processing — primarily to cut off small fragments around the mask edges. That said, SegNext works reasonably well as an interactive tool: providing both foreground (positive) and background (negative) points produces decent results. One additional limitation: SegNext does not support box prompts, which is a minor disadvantage compared to SAM. |
|
@andriiryzhkov : Where is the model to test? From dt it cannot be downloaded (not found) and I don't see it in the repo. |
|
It is still from my repository To download models from |
|
@andriiryzhkov : Maybe something messed up on my side then. I do have But on UI it is has the not downloaded status:
And if I try to download I get:
And if I try the object mask button:
So I'm stuck :) Any idea? |
|
@TurboGit: I should have highlighted this change better - in order to improve models discoverability I decided to limit the models location to the config folder So you just need to move your models:
For download option you need to make sure parameter in
That is current default value in PR. |
Not a good change because the The |
I agree. I run into a problem on Windows with |
|
Just tested a bit, the model is quite slower indeed and I have some issues with the refinement. Use the integration test Capture.video.du.2026-02-26.18-28-06.mp4I have first selected the bottle, and then 2 times clicked on the missed area. I have been able to reproduce on 2 images tested out of 3. BTW, when the masks are computed we need a busy cursor. |
|
SegNext and SAM 2.1 are different models with different design goals, so a direct quality comparison isn't entirely fair. In the context of AI object masking specifically, SegNext is a bit slower and less accurate than SAM 2.1 – though the difference is not huge. In terms of model choice, we still have two options: proceed with SAM 2.1 (small), which is faster and produces better quality masks but carries Meta's data provenance concerns, or go with SegNext (base), which is cleaner in terms of training data transparency. No model produces a perfect mask in every situation – and that's fine. After many years working with AI professionally, the question I always come back to is: does this save the user a significant amount of time to achieve the desired result? If yes, it's worth the trade-offs – even if the model isn't technically flawless. With AI object masking, the output is always a path mask, which means any inaccuracies can be refined manually. The user retains full control; the AI just removes the tedious baseline work. Regarding the bottle selection in the demo – the missing part of the mask is near the edge where two dark bottles are close together. The model simply can't distinguish the boundary in that region. In such situations, no amount of refinement clicks will help: if the model can't perceive the edge, it won't mask it correctly. This is a known limitation of contrast-dependent segmentation, not a bug. Personally, I would lean towards SAM 2.1 – but I don't want this choice to become a divisive topic for the community. I'm happy to go with whatever direction we reach consensus on.
Noted. |
I agree with that, but here I'm not comparing but more trying to see what could be the best for Darktable. I'll continue testing. At the moment the situation of SegNext is not compelling.
Exactly, and for me at the moment I'm not sure SegNext qualify.
Agreed too, another alternative is to provides both and let user do the choice.
My feeling at the moment too. Let me do some more tests. Again thanks for the hard work put on this. |
|
Tested again, and to me the SegNext is of poor quality. I would like to be able to propose also from the AI preferences the SAM 2.1 small (not the default) but at least this will give a high quality AI masking option. Having only SegNext will make Darktable looks really bad when compared to the alternatives and at the end this option will certainly not adopted by most people. This is in the spirit of what I want for Darktable, the freedom to use what they found OK for their work depending on their sensitivity about AI and models. |
|
I will prepare PR to add SAM 2.1 models to https://github.com/darktable-org/darktable-ai repository |







Adds a new mask tool that lets users select objects in the image by clicking. Built on the AI subsystem from #20322.
How it works
AI object mask is an interactive single-object selection tool. The user activates the object mask tool, waits for the image to be encoded (background thread), then clicks to place foreground/background point prompts. The model segments the object in real time. Right-click finalizes the selection by vectorizing the raster mask into Bézier path forms that integrate with darktable's existing mask system.
Architecture
Segmentation engine (
src/ai/segmentation.c): Implements the two-stage encoder/decoder pipeline. Supports both SAM2.1 (multi-mask + IoU selection + low-res refinement) and SegNext (single mask, full-res refinement). Encoder outputs are cached so multiple clicks don't re-encode.Object mask tool (
src/develop/masks/object.c): Runs image encoding in a background thread to keep the UI responsive. Displays a "working..." overlay during encoding. Supports foreground clicks (label 1), background clicks (label 0), and box prompts (SAM only).Raster-to-vector (
src/common/ras2vect.c): Extended with cleanup (turdsize), smoothing (alphamax), and boundary sign output for hole detection.Models
The segmentation engine supports both SegNext and SAM model architectures. SegNext is the default — it produces good enough results and is compliant with the Open Source AI Definition. Models are downloaded on demand by the AI subsystem from the model repository: https://github.com/andriiryzhkov/darktable-ai
Depends on #20322
Fixes #12295