Blend tint colors into shadow/highlight regions.
(img: torch.Tensor, shadows_tint: str, highlights_tint: str, balance: float)
| 139 | |
| 140 | |
| 141 | def _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 | |
| 157 | def _apply_vignette(img: torch.Tensor, strength: float) -> torch.Tensor: |
no test coverage detected