|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
|
|
import math |
|
|
|
|
|
|
|
|
|
|
|
import torch |
|
|
|
import torch |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
import os |
|
|
@ -942,28 +944,31 @@ class ImagePadForOutpaint: |
|
|
|
dtype=torch.float32, |
|
|
|
dtype=torch.float32, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t = torch.zeros( |
|
|
|
|
|
|
|
(d2, d3), |
|
|
|
|
|
|
|
dtype=torch.float32 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if feathering > 0 and feathering * 2 < d2 and feathering * 2 < d3: |
|
|
|
if feathering > 0 and feathering * 2 < d2 and feathering * 2 < d3: |
|
|
|
# distances to border |
|
|
|
|
|
|
|
mi, mj = torch.meshgrid( |
|
|
|
for i in range(d2): |
|
|
|
torch.arange(d2, dtype=torch.float32), |
|
|
|
for j in range(d3): |
|
|
|
torch.arange(d3, dtype=torch.float32), |
|
|
|
dt = i if top != 0 else d2 |
|
|
|
indexing='ij', |
|
|
|
db = d2 - i if bottom != 0 else d2 |
|
|
|
) |
|
|
|
|
|
|
|
distances = torch.minimum( |
|
|
|
dl = j if left != 0 else d3 |
|
|
|
torch.minimum(mi, mj), |
|
|
|
dr = d3 - j if right != 0 else d3 |
|
|
|
torch.minimum(d2 - 1 - mi, d3 - 1 - mj), |
|
|
|
|
|
|
|
) |
|
|
|
d = min(dt, db, dl, dr) |
|
|
|
# convert distances to square falloff from 1 to 0 |
|
|
|
|
|
|
|
t = (feathering - distances) / feathering |
|
|
|
if d >= feathering: |
|
|
|
t.clamp_(min=0) |
|
|
|
continue |
|
|
|
t.square_() |
|
|
|
|
|
|
|
|
|
|
|
v = (feathering - d) / feathering |
|
|
|
mask[top:top + d2, left:left + d3] = t |
|
|
|
|
|
|
|
else: |
|
|
|
t[i, j] = v * v |
|
|
|
mask[top:top + d2, left:left + d3] = torch.zeros( |
|
|
|
|
|
|
|
(d2, d3), |
|
|
|
mask[top:top + d2, left:left + d3] = t |
|
|
|
dtype=torch.float32, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (new_image, mask) |
|
|
|
return (new_image, mask) |
|
|
|
|
|
|
|
|
|
|
|