raubatz/1bucket / comfy /custom_nodes /ComfyUI-post-processing-nodes-master /post_processing /canny_edge_mask.py
| import cv2 | |
| import numpy as np | |
| import torch | |
| class CannyEdgeMask: | |
| def __init__(self): | |
| pass | |
| def INPUT_TYPES(s): | |
| return { | |
| "required": { | |
| "image": ("IMAGE",), | |
| "lower_threshold": ("INT", { | |
| "default": 100, | |
| "min": 0, | |
| "max": 500, | |
| "step": 10 | |
| }), | |
| "upper_threshold": ("INT", { | |
| "default": 200, | |
| "min": 0, | |
| "max": 500, | |
| "step": 10 | |
| }), | |
| }, | |
| } | |
| RETURN_TYPES = ("IMAGE",) | |
| FUNCTION = "canny" | |
| CATEGORY = "postprocessing/Masks" | |
| def canny(self, image: torch.Tensor, lower_threshold: int, upper_threshold: int): | |
| batch_size, height, width, _ = image.shape | |
| result = torch.zeros(batch_size, height, width) | |
| for b in range(batch_size): | |
| tensor_image = image[b].numpy().copy() | |
| gray_image = (cv2.cvtColor(tensor_image, cv2.COLOR_RGB2GRAY) * 255).astype(np.uint8) | |
| canny = cv2.Canny(gray_image, lower_threshold, upper_threshold) | |
| tensor = torch.from_numpy(canny) | |
| result[b] = tensor | |
| return (result,) | |
| NODE_CLASS_MAPPINGS = { | |
| "CannyEdgeMask": CannyEdgeMask | |
| } | |
Xet Storage Details
- Size:
- 1.4 kB
- Xet hash:
- f02b39197c07d1f30a43b532f88675c3fa950e0f11458e15f21d929100742e21
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.