mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2026-06-08 03:57:53 +08:00
Fix case of rows 0
This commit is contained in:
parent
488e6607fe
commit
022b499c70
@ -3186,7 +3186,6 @@ class LoadImagesFromFolderKJ:
|
|||||||
stat = ImageStat.Stat(edges)
|
stat = ImageStat.Stat(edges)
|
||||||
median = tuple(map(int, stat.median))
|
median = tuple(map(int, stat.median))
|
||||||
return median
|
return median
|
||||||
|
|
||||||
|
|
||||||
class ImageGridtoBatch:
|
class ImageGridtoBatch:
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -3197,37 +3196,38 @@ class ImageGridtoBatch:
|
|||||||
"rows": ("INT", {"default": 0, "min": 1, "max": 8, "tooltip": "The number of rows in the grid. Set to 0 for automatic calculation."}),
|
"rows": ("INT", {"default": 0, "min": 1, "max": 8, "tooltip": "The number of rows in the grid. Set to 0 for automatic calculation."}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_TYPES = ("IMAGE",)
|
RETURN_TYPES = ("IMAGE",)
|
||||||
FUNCTION = "decompose"
|
FUNCTION = "decompose"
|
||||||
CATEGORY = "KJNodes/image"
|
CATEGORY = "KJNodes/image"
|
||||||
DESCRIPTION = "Converts a grid of images to a batch of images."
|
DESCRIPTION = "Converts a grid of images to a batch of images."
|
||||||
|
|
||||||
def decompose(self, image, columns, rows):
|
def decompose(self, image, columns, rows):
|
||||||
B, H, W, C = image.shape
|
B, H, W, C = image.shape
|
||||||
print("input size: ", image.shape)
|
print("input size: ", image.shape)
|
||||||
|
|
||||||
# Calculate cell width, rounding down
|
# Calculate cell width, rounding down
|
||||||
cell_width = W // columns
|
cell_width = W // columns
|
||||||
|
|
||||||
if rows == 0:
|
if rows == 0:
|
||||||
# If rows is 0, calculate number of full rows
|
# If rows is 0, calculate number of full rows
|
||||||
|
cell_height = H // columns
|
||||||
rows = H // cell_height
|
rows = H // cell_height
|
||||||
else:
|
else:
|
||||||
# If rows is specified, adjust cell_height
|
# If rows is specified, adjust cell_height
|
||||||
cell_height = H // rows
|
cell_height = H // rows
|
||||||
|
|
||||||
# Crop the image to fit full cells
|
# Crop the image to fit full cells
|
||||||
image = image[:, :rows*cell_height, :columns*cell_width, :]
|
image = image[:, :rows*cell_height, :columns*cell_width, :]
|
||||||
|
|
||||||
# Reshape and permute the image to get the grid
|
# Reshape and permute the image to get the grid
|
||||||
image = image.view(B, rows, cell_height, columns, cell_width, C)
|
image = image.view(B, rows, cell_height, columns, cell_width, C)
|
||||||
image = image.permute(0, 1, 3, 2, 4, 5).contiguous()
|
image = image.permute(0, 1, 3, 2, 4, 5).contiguous()
|
||||||
image = image.view(B, rows * columns, cell_height, cell_width, C)
|
image = image.view(B, rows * columns, cell_height, cell_width, C)
|
||||||
|
|
||||||
# Reshape to the final batch tensor
|
# Reshape to the final batch tensor
|
||||||
img_tensor = image.view(-1, cell_height, cell_width, C)
|
img_tensor = image.view(-1, cell_height, cell_width, C)
|
||||||
|
|
||||||
return (img_tensor,)
|
return (img_tensor,)
|
||||||
|
|
||||||
class SaveImageKJ:
|
class SaveImageKJ:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user