mask upload

This commit is contained in:
lllyasviel
2024-01-02 08:21:50 -08:00
parent b5163e057f
commit e5af760db8
6 changed files with 56 additions and 54 deletions
+10
View File
@@ -3,6 +3,7 @@ import datetime
import random
import math
import os
import cv2
from PIL import Image
@@ -10,6 +11,15 @@ from PIL import Image
LANCZOS = (Image.Resampling.LANCZOS if hasattr(Image, 'Resampling') else Image.LANCZOS)
def erode_or_dilate(x, k):
k = int(k)
if k > 0:
return cv2.dilate(x, kernel=np.ones(shape=(3, 3), dtype=np.uint8), iterations=k)
if k < 0:
return cv2.erode(x, kernel=np.ones(shape=(3, 3), dtype=np.uint8), iterations=-k)
return x
def resample_image(im, width, height):
im = Image.fromarray(im)
im = im.resize((int(width), int(height)), resample=LANCZOS)