From ec93ee7eae2e94e5f00d66618ccbb94bacf445eb Mon Sep 17 00:00:00 2001 From: mercu-lore <66737692+mercu-lore@users.noreply.github.com> Date: Wed, 12 Nov 2025 15:46:36 +0100 Subject: [PATCH] Add files via upload --- README.md | 5 +++-- region_crop_node.py | 10 +++++----- region_selector_node.py | 16 ++++++++-------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cb39dd7..a0da6f1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Interactive interface to select rectangular regions on images. #### Output - `image` (IMAGE): Original image (passthrough) -- `region_metadata` (STRING): JSON with selection coordinates +- `box_metadata` (STRING): JSON with selection coordinates #### Features - 🖱️ **Interactive Selection**: Click and drag to draw rectangles @@ -60,7 +60,8 @@ Crops images according to coordinates provided by BoxSelector. #### Input - `image` (IMAGE): Image to crop -- `region_metadata` (STRING): JSON coordinates from BoxSelector (x1, x2, y1, y2) +- `box_metadata` (STRING): JSON coordinates from BoxSelector (x1, x2, y1, y2) + - Connect directly from BoxSelector output #### Optional Input - `fallback_mode` (COMBO): Behavior when no valid coordinates diff --git a/region_crop_node.py b/region_crop_node.py index c4dc643..0181447 100644 --- a/region_crop_node.py +++ b/region_crop_node.py @@ -23,8 +23,8 @@ class RegionCropNode: return { "required": { "image": ("IMAGE",), - "region_metadata": ("STRING", { - "default": "{}", + "box_metadata": ("STRING", { + "default": "", "multiline": True, }), }, @@ -40,13 +40,13 @@ class RegionCropNode: FUNCTION = "crop_image" CATEGORY = "image/region" - def crop_image(self, image, region_metadata, fallback_mode="use_full_image"): + def crop_image(self, image, box_metadata, fallback_mode="use_full_image"): """ Taglia l'immagine secondo le coordinate nel metadata. Args: image: Tensor immagine (B, H, W, C) - region_metadata: JSON string con coordinate della regione + box_metadata: JSON string con coordinate della regione fallback_mode: Cosa fare se non ci sono coordinate valide Returns: @@ -54,7 +54,7 @@ class RegionCropNode: """ try: - metadata = json.loads(region_metadata) + metadata = json.loads(box_metadata) if box_metadata.strip() else {} except json.JSONDecodeError: metadata = {} diff --git a/region_selector_node.py b/region_selector_node.py index 22c5eaf..83a88ee 100644 --- a/region_selector_node.py +++ b/region_selector_node.py @@ -1,7 +1,7 @@ """ -Region Selector Node - con endpoint di ridimensionamento lato backend. -Riduce automaticamente le immagini oltre 1024px quando viene aperta -l'interfaccia "Select Box", salvandole in /temp/. +BoxSelector Node - Interactive region selection with auto-scaling for large images. +Automatically scales images > 1024px in preview for smooth selection. +Outputs box_metadata with coordinates and displayScaleFactor. """ import os @@ -23,18 +23,18 @@ class RegionSelectorNode: def INPUT_TYPES(cls): return { "required": {"image": ("IMAGE",)}, - "optional": {"region_metadata": ("STRING", {"default": "{}", "multiline": True})} + "optional": {"box_metadata": ("STRING", {"default": "", "multiline": True})} } RETURN_TYPES = ("IMAGE", "STRING") - RETURN_NAMES = ("image", "region_metadata") + RETURN_NAMES = ("image", "box_metadata") FUNCTION = "process_region_selection" CATEGORY = "image/region" OUTPUT_NODE = True - def process_region_selection(self, image, region_metadata="{}"): - if region_metadata.strip() and region_metadata != "{}": - self.last_metadata = region_metadata + def process_region_selection(self, image, box_metadata="{}"): + if box_metadata.strip() and box_metadata != "{}": + self.last_metadata = box_metadata return (image, self.last_metadata)