ComfyUI Node
BD Luminance Mask
Extract top X% brightest and bottom Y% darkest pixels as separate masks. Uses np.percentile so thresholds adapt to image content (dark images still produce a useful highlight mask from their brightest regions). Optional mask_within restricts the percentile computation to a region — e.g. pass the skin mask so clothes/background don't skew the percentiles.
BD Luminance Mask
- image
- mask
- highlight_mask
- dark_mask
- threshold_hi
- threshold_lo
◄luma_standardbt709►
◄top_percent10.00►
◄bottom_percent8.00►
◄exclude_above1.00►
◄exclude_below0.00►
◄top_soft_edge0.030►
◄bottom_soft_edge0.030►
◄smooth_pixels0►
◄gradient_modefalse►
◄gradient_curve1.00►
Category🧠BrainDead/Segmentation
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Source image. Luminance computed via the selected weighting. | |
| luma_standard | COMBO | bt709 | RGB → luminance weighting: bt709 (default): 0.2126 R + 0.7152 G + 0.0722 B — modern sRGB/Rec.709 standard. Use for Unity/Unreal, AI pipelines, modern display work. bt601: 0.299 R + 0.587 G + 0.114 B — legacy NTSC weights, matches Photoshop 'Desaturate' and older tools. average: (R+G+B)/3 — simple, not perceptual. |
| top_percent | FLOAT | 10.000–50 | Extract pixels in the top X% of luminance. Set to 0 to disable highlight output. If your image has lots of pure-white pixels (reflections, background), the percentile will collapse to 1.0 — use exclude_above to clip those out first. |
| bottom_percent | FLOAT | 8.000–50 | Extract pixels in the bottom Y% of luminance. Set to 0 to disable dark output. If your image has lots of pure-black pixels (background, lines), use exclude_below. |
| exclude_above | FLOAT | 1.000–1 | Pixels with luminance ABOVE this are excluded from BOTH the percentile calculation AND the output mask. Use to ignore pure-white reflections/background (e.g. 0.95 excludes pixels brighter than 95%). Default 1.0 = no exclusion. |
| exclude_below | FLOAT | 0.000–1 | Pixels with luminance BELOW this are excluded from BOTH the percentile calculation AND the output mask. Use to ignore pure-black background/lines (e.g. 0.05 excludes pixels darker than 5%). Default 0.0 = no exclusion. |
| top_soft_edge | FLOAT | 0.0300–0.3 | Soft edge BELOW the highlight threshold — pixels at or above thr_hi are fully selected (=1), pixels in [thr_hi - top_soft_edge, thr_hi] ramp 0→1. 0 = hard binary edge. Bigger = wider luma-range feather (smooths threshold). |
| bottom_soft_edge | FLOAT | 0.0300–0.3 | Soft edge ABOVE the dark threshold — pixels at or below thr_lo are fully selected (=1), pixels in [thr_lo, thr_lo + bottom_soft_edge] ramp 1→0. 0 = hard binary edge. Bigger = wider luma-range feather. |
| smooth_pixels | FLOAT | 00–200 | SPATIAL gaussian blur radius in pixels applied to BOTH output masks. This spreads the mask spatially (softens chunk edges) but doesn't change the value relationships. Typical: 4-16 subtle, 32+ heavy. 0 = no blur. |
| gradient_mode | BOOLEAN | false | When ON: mask values become a SMOOTH RAMP based on how far each pixel's luminance is from the threshold toward the extreme. Brightest pixel = white, threshold pixel = black, smooth gradient between (no binary cutoff). Ignores soft_edge. This is the 'fade from white to black' look — different from smooth_pixels (which is spatial blur). |
| gradient_curve | FLOAT | 1.000.2–4 | Shape of the gradient ramp (only when gradient_mode is ON). 1.0 = linear. <1 (e.g. 0.5 = sqrt) ramps quickly toward white. >1 (e.g. 2.0) keeps most pixels dark, only brightest reach white. |
| maskopt | MASK | Optional region mask. When provided, percentile calculation only considers pixels where this mask > 0.5 (typically the skin mask). Output masks are also restricted to this region (zero outside). |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| highlight_mask | IMAGE | White (1) where pixels are in the top X% of luminance, black (0) elsewhere. |
| dark_mask | IMAGE | White (1) where pixels are in the bottom Y% of luminance, black (0) elsewhere. |
| threshold_hi | FLOAT | The computed luminance threshold above which pixels become highlight_mask=1. |
| threshold_lo | FLOAT | The computed luminance threshold below which pixels become dark_mask=1. |