Skip to content

[AI] Replace edge refinement with guided filter in object mask#20622

Merged
TurboGit merged 3 commits intodarktable-org:masterfrom
andriiryzhkov:mask_guided_filter
Mar 24, 2026
Merged

[AI] Replace edge refinement with guided filter in object mask#20622
TurboGit merged 3 commits intodarktable-org:masterfrom
andriiryzhkov:mask_guided_filter

Conversation

@andriiryzhkov
Copy link
Copy Markdown
Contributor

Summary

  • Replace custom Scharr gradient edge refinement with darktable's built-in guided filter for mask boundary snapping
  • Add configurable render resolution for higher-quality edge refinement and vectorization

Edge refinement

The previous approach computed Scharr gradients and modulated the binarization threshold near edges. The new approach uses guided_filter() from common/guided_filter.h (same filter used by blend.c for drawn mask feathering). It smooths the SAM mask in flat regions while preserving sharp transitions at image edges, producing cleaner object boundaries.

Two configurable parameters (in darktablerc):

  • guided_radius (0-20, default 5): filter window size. 0 disables the filter
  • guided_eps (0.001-1.0, default 0.01): edge sensitivity. smaller = sharper edges

Render resolution

The render resolution is now configurable via render_size (default 1024, minimum 1024, no upper limit). The SAM encoder always works at 1024px internally, but higher render resolution gives the guided filter and vectorizer more pixels to work with, improving edge accuracy at the cost of processing time.

Users with powerful hardware can increase this for better results:

plugins/darkroom/masks/object/render_size=2048

@andriiryzhkov andriiryzhkov marked this pull request as draft March 22, 2026 07:09
@andriiryzhkov andriiryzhkov marked this pull request as ready for review March 22, 2026 11:50
@TurboGit TurboGit added this to the 5.6 milestone Mar 24, 2026
@TurboGit TurboGit added priority: medium core features are degraded in a way that is still mostly usable, software stutters feature: redesign current features to rewrite labels Mar 24, 2026
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.

Works for me, thanks!

@TurboGit TurboGit merged commit 74ffeaf into darktable-org:master Mar 24, 2026
5 checks passed
@andriiryzhkov andriiryzhkov deleted the mask_guided_filter branch March 25, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: redesign current features to rewrite priority: medium core features are degraded in a way that is still mostly usable, software stutters

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants