MCPcopy
hub / github.com/vladmandic/sdnext / _apply_split_toning

Function _apply_split_toning

modules/processing_grading.py:141–154  ·  view source on GitHub ↗

Blend tint colors into shadow/highlight regions.

(img: torch.Tensor, shadows_tint: str, highlights_tint: str, balance: float)

Source from the content-addressed store, hash-verified

139
140
141def _apply_split_toning(img: torch.Tensor, shadows_tint: str, highlights_tint: str, balance: float) -> torch.Tensor:
142 """Blend tint colors into shadow/highlight regions."""
143 kornia = _ensure_kornia()
144 lab = kornia.color.rgb_to_lab(img)
145 L = lab[:, 0:1, :, :] / 100.0
146 shadow_rgb = _hex_to_rgb(shadows_tint)
147 highlight_rgb = _hex_to_rgb(highlights_tint)
148 shadow_color = torch.tensor(shadow_rgb, dtype=img.dtype, device=img.device).view(1, 3, 1, 1)
149 highlight_color = torch.tensor(highlight_rgb, dtype=img.dtype, device=img.device).view(1, 3, 1, 1)
150 shadow_mask = ((1.0 - L) * (1.0 - balance)).clamp(0, 1)
151 highlight_mask = (L * balance).clamp(0, 1)
152 img = img * (1.0 - shadow_mask * 0.3) + shadow_color * shadow_mask * 0.3
153 img = img * (1.0 - highlight_mask * 0.3) + highlight_color * highlight_mask * 0.3
154 return img.clamp(0, 1)
155
156
157def _apply_vignette(img: torch.Tensor, strength: float) -> torch.Tensor:

Callers 1

grade_imageFunction · 0.85

Calls 3

_ensure_korniaFunction · 0.85
_hex_to_rgbFunction · 0.85
viewMethod · 0.80

Tested by

no test coverage detected