Add files via upload
This commit is contained in:
@@ -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
|
||||
|
||||
+5
-5
@@ -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 = {}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user