feat : calc mask bound

This commit is contained in:
apsntian
2024-03-20 17:07:32 +09:00
parent d67f12a30a
commit ad7cc97c7a
2 changed files with 58 additions and 3 deletions
+5 -3
View File
@@ -1,5 +1,5 @@
from .modules.image_loader import CachedLoadImageFromUrl
from .modules.image_tool import OFFCenterCrop, OFFCenterCropSEGS, OFFSEGSToImage, OFFImageResizeFit, OFFWatermark, MaskToImageFallback, MaskDilationForEachFace, SegsToFaceCropData, PasteFaceSegToImage, OFFCLAHE,OffGridImageBatch
from .modules.image_tool import OFFCenterCrop, OFFCenterCropSEGS, OFFSEGSToImage, OFFImageResizeFit,OFFWatermark, MaskToImageFallback, MaskDilationForEachFace, SegsToFaceCropData, PasteFaceSegToImage, OFFCLAHE,OffGridImageBatch, CalcMaskBound
from .modules.misc import GWNumFormatter, QueryGenderAge, RandomSeedFromList
from .modules.latent_tool import VAEEncodeForInpaintV2
@@ -23,7 +23,8 @@ NODE_CLASS_MAPPINGS = {
"Paste Face Segment to Image" : PasteFaceSegToImage,
"Apply CLAHE" : OFFCLAHE,
"Grid Image from batch (OFF)" : OffGridImageBatch,
"RandomSeedfromList" : RandomSeedFromList
"RandomSeedfromList" : RandomSeedFromList,
"CalcMaskBound":CalcMaskBound
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
@@ -44,5 +45,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"Paste Face Segment to Image":"Paste Face Segment to Image",
"Apply CLAHE":"Apply CLAHE",
"Grid Image from batch (OFF)" : "Grid Image from batch (OFF)",
"RandomSeedfromList" : "Random Seed from List"
"RandomSeedfromList" : "Random Seed from List",
"CalcMaskBound": "Calculate mask bound"
}
+53
View File
@@ -482,3 +482,56 @@ class OffGridImageBatch:
new_image = ImageOps.expand(new_image, border=outer_border_width, fill=border_color)
return (pil2tensor(new_image), )
class CalcMaskBound:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
"padding":("INT",{"default":0, "min": 0, "step":1})
}
}
CATEGORY = "OFF"
RETURN_TYPES = ("INT","INT","INT","INT",)
FUNCTION = "process"
def process(self, mask, padding):
rows, cols = np.where(mask[0])
min_row, max_row = rows.min(), rows.max()
min_col, max_col = cols.min(), cols.max()
min_col -= padding
min_row -= padding
max_col += padding
max_row += padding
if min_col< 0 :
min_col = 0
if min_row<0:
min_row = 0
if max_row > mask.shape[1]:
max_row = mask.shape[1]
if max_col > mask.shape[2]:
max_col = mask.shape[2]
return (min_col, min_row, max_col - min_col, max_row - min_row, )