Skip to content

BUG: Fix LabelMapMaskImageFilter BackgroundValue cast through label type - #2629

Merged
blowekamp merged 1 commit into
SimpleITK:mainfrom
blowekamp:fix_label_map_mask_background_value
Jul 21, 2026
Merged

blowekamp merged 1 commit into
SimpleITK:mainfrom
blowekamp:fix_label_map_mask_background_value

Conversation

@blowekamp

@blowekamp blowekamp commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes issue #2625 (S16): BackgroundValue in LabelMapMaskImageFilter was silently losing negative values due to a wrong cast.

Root Cause

BackgroundValue was declared pixeltype: Output, but no output_image_type was set in the YAML. The dual template's fallback assigns OutputImageType = InputImageType — the LabelMap type (unsigned integer). This caused the double background value to be static_cast to the unsigned label pixel type before being forwarded to ITK, destroying any negative or non-integer value.

Fix

Add output_image_type: InputImageType2 to LabelMapMaskImageFilter.yaml, making OutputImageType alias the feature image type as ITK's filter intends.

Test

Added BasicFilters.LabelMapMaskImageFilter_BackgroundValuePreserved in sitkBasicFiltersTests.cxx: runs the filter with a float feature image and BackgroundValue = -1000.0, asserts the output minimum is -1000.0.

@blowekamp
blowekamp force-pushed the fix_label_map_mask_background_value branch 2 times, most recently from 716c58b to 915a9d5 Compare July 15, 2026 19:54
BackgroundValue was cast to the LabelMap pixel type (unsigned) instead of
the feature image type, silently destroying negative values. Fix by adding
output_image_type: InputImageType2 to the yaml. Adds a C++ regression test.

Fixes SimpleITK#2625 (S16)
@blowekamp
blowekamp force-pushed the fix_label_map_mask_background_value branch from 915a9d5 to ce3a532 Compare July 20, 2026 20:20
@blowekamp
blowekamp marked this pull request as ready for review July 21, 2026 13:10
@blowekamp
blowekamp requested review from dave3d and zivy July 21, 2026 13:10
@blowekamp
blowekamp merged commit ca7a0e4 into SimpleITK:main Jul 21, 2026
10 checks passed
@blowekamp
blowekamp deleted the fix_label_map_mask_background_value branch September 9, 2026 12:55
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.

2 participants