Skip to content

Commit 8a9f50f

Browse files
authored
Add pixel width to seam mask node
1 parent d8bc82f commit 8a9f50f

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

nodes.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -897,14 +897,15 @@ def run(
897897

898898

899899
def _create_center_seam_mask(
900-
x: torch.Tensor, frac_width: float = 0.10, feather: int = 0
900+
x: torch.Tensor, frac_width: float = 0.10, pixel_width: int = 0, feather: int = 0
901901
) -> torch.Tensor:
902902
"""
903903
For a ComfyUI-style mask: shape [B, H, W], values 0 or 1, with optional feathering.
904904
905905
Args:
906906
x (torch.Tensor): input tensor with shape [B, H, W, C].
907907
frac_width (float, optional): fraction of input width for the vertical strip.
908+
pixel_width (int, optional): width of the seam in pixels (if > 0).
908909
feather (int, optional): pixel size of feathering on both sides of the mask.
909910
910911
Returns:
@@ -913,7 +914,12 @@ def _create_center_seam_mask(
913914
# Extract batch, height, and width from x
914915
B, H, W, *_ = x.shape
915916

916-
strip = max(1, int(W * frac_width))
917+
# Determine strip width
918+
if pixel_width > 0:
919+
strip = pixel_width
920+
else:
921+
strip = max(1, int(W * frac_width))
922+
917923
x0 = (W - strip) // 2
918924
x1 = x0 + strip
919925

@@ -970,7 +976,15 @@ def INPUT_TYPES(s) -> Dict:
970976
return {
971977
"required": {
972978
"image": ("IMAGE", {"default": None}),
973-
"seam_mask_width": ("FLOAT", {"default": 0.10}),
979+
"frac_width": ("FLOAT", {"default": 0.10}),
980+
"pixel_width": (
981+
"INT",
982+
{
983+
"default": 0,
984+
"tooltip": "Width of the seam in pixels."
985+
+ " If > 0, frac_width is ignored in favour of width_pixel.",
986+
},
987+
),
974988
"feather": (
975989
"INT",
976990
{"default": 0, "tooltip": "Pixel size of the feathering."},
@@ -996,15 +1010,16 @@ def INPUT_TYPES(s) -> Dict:
9961010
def run(
9971011
self,
9981012
image: torch.Tensor,
999-
seam_mask_width: float = 0.10,
1013+
frac_width: float = 0.10,
1014+
pixel_width: int = 0,
10001015
feather: int = 0,
10011016
roll_x_by_50_percent: bool = False,
10021017
) -> Tuple[torch.Tensor]:
10031018
assert image.dim() == 4, "Image should have 4 dimensions"
10041019
_, H, W, _ = image.shape
10051020
px_half = W // 2
10061021
seam_mask = _create_center_seam_mask(
1007-
image, frac_width=seam_mask_width, feather=feather
1022+
image, frac_width=frac_width, pixel_width=pixel_width, feather=feather
10081023
)
10091024

10101025
if roll_x_by_50_percent:
@@ -1147,7 +1162,7 @@ def INPUT_TYPES(s) -> Dict:
11471162
}
11481163

11491164
RETURN_TYPES = ("MASK",)
1150-
RETURN_NAMES = ("Seam Mask",)
1165+
RETURN_NAMES = ("Pole Mask",)
11511166

11521167
FUNCTION = "run"
11531168

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-pytorch360convert"
33
description = "A collection of custom nodes for working with and converting between and working with 360 degree equirectangular images, cubemap, and perspective images. Also includes Circular padding Conv2d options for models and VAEs, along with nodes to fix seams and polar artifacts. Panoramic 360 images are also sometimes known as VR photography (virtual reality), HDRI environments (ex: skyboxes), image spheres, spherical images, 360 pano."
4-
version = "1.1.1"
4+
version = "1.1.2"
55
license = {file = "LICENSE"}
66
dependencies = ["pytorch360convert"]
77

0 commit comments

Comments
 (0)