raubatz/1bucket / comfy /custom_nodes /ComfyUI-post-processing-nodes-master /post_processing /vignette.py
| import numpy as np | |
| import torch | |
| class Vignette: | |
| def __init__(self): | |
| pass | |
| def INPUT_TYPES(s): | |
| return { | |
| "required": { | |
| "image": ("IMAGE",), | |
| "vignette": ("FLOAT", { | |
| "default": 0.0, | |
| "min": 0.0, | |
| "max": 10.0, | |
| "step": 0.01 | |
| }), | |
| }, | |
| } | |
| RETURN_TYPES = ("IMAGE",) | |
| FUNCTION = "apply_vignette" | |
| CATEGORY = "postprocessing/Effects" | |
| def apply_vignette(self, image: torch.Tensor, vignette: float): | |
| if vignette == 0: | |
| return (image,) | |
| height, width, _ = image.shape[-3:] | |
| x = torch.linspace(-1, 1, width, device=image.device) | |
| y = torch.linspace(-1, 1, height, device=image.device) | |
| X, Y = torch.meshgrid(x, y, indexing="ij") | |
| radius = torch.sqrt(X ** 2 + Y ** 2) | |
| radius = radius / torch.amax(radius, dim=(0, 1), keepdim=True) | |
| opacity = torch.tensor(vignette, device=image.device) | |
| opacity = torch.clamp(opacity, 0.0, 1.0) | |
| vignette = 1 - radius.unsqueeze(0).unsqueeze(-1) * opacity | |
| vignette_image = torch.clamp(image * vignette, 0, 1) | |
| return (vignette_image,) | |
| NODE_CLASS_MAPPINGS = { | |
| "Vignette": Vignette, | |
| } | |
Xet Storage Details
- Size:
- 1.37 kB
- Xet hash:
- 931f5522fe4cb4a4b4ba3f9935b60954b16be85a950e8b02c5f6fd40d593dc16
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.