Skip to content

[AI] Add raster mask export for object masks#20646

Open
andriiryzhkov wants to merge 1 commit intodarktable-org:masterfrom
andriiryzhkov:mask_save_raster
Open

[AI] Add raster mask export for object masks#20646
andriiryzhkov wants to merge 1 commit intodarktable-org:masterfrom
andriiryzhkov:mask_save_raster

Conversation

@andriiryzhkov
Copy link
Copy Markdown
Contributor

Another small improvement. Not 100% sure about it, but maybe helpful for someone.

Adds the ability to export the SAM segmentation mask as an RGB PNG file, compatible with the external raster masks module. Triggered by shift+right-click during object mask creation.

How it works

  • Shift+right-click saves the raster mask as PNG, then applies the vectorized mask as usual
  • Right-click (without shift) applies the mask normally, no file saved
  • Zero friction for the default workflow – no extra config or UI elements

Output format

  • RGB PNG (R=G=B=mask value) compatible with the rasterfile IOP module
  • Binary mask: 255 for foreground, 0 for background (uses the same threshold as vectorization)
  • Saved to the raster mask root folder configured in Preferences → Processing → "raster mask files root folder" (plugins/darkroom/segments/def_path)
  • Filename: {image_name}_mask.png, auto-incremented (_1, _2, ...) if file exists

Copy link
Copy Markdown
Member

@TurboGit TurboGit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly I'm not sure if it is useful or not. I certainly won't use this, but that's only me. I cannot come with a scenario where this will be handy at the moment.

if(!root || !*root)
{
g_free(root);
dt_control_log(_("set raster mask root folder in preferences"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not in preference but in Raster File module.

Copy link
Copy Markdown
Contributor Author

@andriiryzhkov andriiryzhkov Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in Preferences -> processing -> raster mask files root folder. It's a default location.

@deekayhd
Copy link
Copy Markdown
Contributor

Frankly I'm not sure if it is useful or not. I certainly won't use this, but that's only me. I cannot come with a scenario where this will be handy at the moment.

If I understand correctly, this would allow to have a more precise mask than the vectorized mask (e.g. for rugged edges).

@andriiryzhkov
Copy link
Copy Markdown
Contributor Author

Not sure, if there will be any quality benefits. Vectorisation is pretty accurate if you keep smoothing at 0. Maybe at some edge cases.

But that adds dependency on an external file. So pipe willing work correctly without it.

@deekayhd
Copy link
Copy Markdown
Contributor

Not sure, if there will be any quality benefits. Vectorisation is pretty accurate if you keep smoothing at 0. Maybe at some edge cases.

Ok, never mind. I thought this a mitigation for what was discussed in this posting on pixls.us
https://discuss.pixls.us/t/testing-ai-object-masks-in-darktable-nightly-builds/56684/27?u=deekay

@andriiryzhkov
Copy link
Copy Markdown
Contributor Author

Frankly I'm not sure if it is useful or not. I certainly won't use this, but that's only me.

Me too. But I saw people asking about it. And it's not a big feature, so decided to propose it. We can keep it for later if there will be more requests.

@andriiryzhkov
Copy link
Copy Markdown
Contributor Author

@deekayhd :

I thought this a mitigation for what was discussed in this posting on pixls.us

It is exactly for that purpose. Just not sure if it will help much with fine details on edges. But idea is that it might be useful for someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants