Skip to content

Fix segmentation preprocessing to pixel-centre sampling - #21797

Merged
TurboGit merged 1 commit into
darktable-org:masterfrom
andriiryzhkov:fix_segmentation_preprocessing
Aug 10, 2026
Merged

Fix segmentation preprocessing to pixel-centre sampling#21797
TurboGit merged 1 commit into
darktable-org:masterfrom
andriiryzhkov:fix_segmentation_preprocessing

Conversation

@andriiryzhkov

Copy link
Copy Markdown
Collaborator

Follow-up to #21764

That PR fixed the mask side, but _preprocess_image() still samples at y / scale, so the encoder sees the image shifted by 0.5/scale - 0.5 source pixels and bakes that into every mask. It is a uniform shift, so it does not cancel anywhere: 1.5 px at 4000 → 1024, 2.4 px at 6000 → 1024, 5.4 px at 6000 → 512.

With both ends on the same convention the round trip is exact. The MAX(..., 0.0f) keeps (int) a floor and fy >= 0, same as in _crop_resize_mask; I swept the usual sizes and found no index outside the source and no weight outside [0, 1).

SEG_CACHE_VERSION goes to 2 because the cache stores encoder outputs, which are now different numbers. Its key (imgid, distort hash, model) cannot notice a code change, so otherwise previously opened images would keep serving embeddings from the old sampling. Cost is one re-encode per cached image.

@andriiryzhkov andriiryzhkov added this to the 5.8 milestone Aug 10, 2026
@andriiryzhkov andriiryzhkov added bugfix pull request fixing a bug scope: AI features AI features related issues and PR labels Aug 10, 2026

@TurboGit TurboGit left a comment

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.

Thanks!

@TurboGit
TurboGit merged commit 837eedf into darktable-org:master Aug 10, 2026
5 checks passed
@andriiryzhkov
andriiryzhkov deleted the fix_segmentation_preprocessing branch August 11, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix pull request fixing a bug scope: AI features AI features related issues and PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants