Skip to content

Commit

Permalink
fix mask output bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chflame163 committed Jan 17, 2024
1 parent 63fff61 commit b4f2843
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions py/comfy_wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ def tensor2pil(image):
def pil2tensor(image):
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)

def getRGBAmask(image):
ret_mask = torch.tensor([pil2tensor(image)[0, :, :, 3].tolist()])
return ret_mask

def img_whitebackground(image):
if image.mode != 'RGBA':
image = image.convert('RGBA')
width = image.width
height = image.height
img_new = Image.new('RGB', size=(width, height), color=(255, 255, 255))
img_new.paste(image, (0, 0), mask=image)

return img_new

class ComfyWordCloud:
Expand Down Expand Up @@ -201,7 +204,7 @@ def wordcloud(self, text, width, height, margin, scale, font_path,
wc.recolor(color_func=image_colors)

ret_image = wc.to_image().convert('RGBA')
ret_mask = pil2tensor(ret_image)[0, :, :, 3]
ret_mask = getRGBAmask(ret_image)

return (pil2tensor(ret_image), ret_mask,)

Expand Down

0 comments on commit b4f2843

Please sign in to comment.