Description
I love to use darktable for editing my photos but my main annoyance is that I still need to hand-draw masks for portraits and this can get to a lot of masks quickly....
Therefore I thought I'd give it a shot to see if I could use the output of Segment Anything 2 in Darktable to save me from manually making all these masks! A screenshot of the ui that i whipped up:
r/DarkTable - Working on a simple Segment Anything 2 integration for Darktable, looking for input
My current approach is:
Select some points in the image and let Segment Anything do it's magic
Convert the points to the format that the Path mask uses (I'd change the `darktable:mask_points)
<rdf:li
darktable:mask_num="11"
darktable:mask_id="1736033909"
darktable:mask_type="2"
darktable:mask_name="path #2"
darktable:mask_version="6"
darktable:mask_points="gz03eJzL+hFttylZwj4Ljea6rmwDwowMDAwqr2PsEgX47NFpZDVHVyTaxYr+sUOnkdUAAAAHJBY="
darktable:mask_nb="3"
darktable:mask_src="0000000000000000"/>
</rdf:Seq>
- Reopen darktable to reload the xmp file with the newly added masks
Some problems / thoughts that I currently have:
-
I'm currently facing some issues when writing back the points to the file. Reading and editing points (translate a mask) is currently no problem for my code but when I replace the mask's path points with the output of the masking code I get masks in very weird shapes
-
It does not really feel right first extract the outline from the mask and use that as a mask. Using the mask defined on the pixels would be a lot nicer, is there any way that I can get a custom image into the intermediate masks in the rendering pipeline?
Some input from darktable devs who know a lot better then me how this all works would be really appreciated! I've also been looking if it would be nice to convert this into a darktable plugin when it's working reliably but I've had a a lot of trouble finding good resources...
I've also read through the LUA API docs but didn't find any functionality there to alter masks. Maybe there is a way to accomplish this that I didn't find in the docs??
Here is the code:
https://github.com/kalmjasper/segmentanything_darktable