Spaces:
Build error
Build error
Sophie98
commited on
Commit
•
91c0967
1
Parent(s):
23deeaa
fix final cropping
Browse files- styleTransfer.py +10 -5
styleTransfer.py
CHANGED
@@ -6,19 +6,24 @@ import cv2
|
|
6 |
|
7 |
def resize_sofa(img):
|
8 |
img = Image.fromarray(img)
|
9 |
-
width, height = img.size
|
10 |
idx = np.argmin([width,height])
|
11 |
newsize = (640, 640) # parameters from test script
|
12 |
|
13 |
if idx==0:
|
14 |
img1 = Image.new(img.mode, (height, height), (255, 255, 255))
|
15 |
img1.paste(img, ((height-width)//2, 0))
|
16 |
-
box = (
|
|
|
|
|
|
|
17 |
else:
|
18 |
img1 = Image.new(img.mode, (width, width), (255, 255, 255))
|
19 |
-
img1.paste(img, (0, (width-height)//2))
|
20 |
-
box = (0,
|
21 |
-
|
|
|
|
|
22 |
im1 = img1.resize(newsize)
|
23 |
return im1,box
|
24 |
|
|
|
6 |
|
7 |
def resize_sofa(img):
|
8 |
img = Image.fromarray(img)
|
9 |
+
width, height = img.size
|
10 |
idx = np.argmin([width,height])
|
11 |
newsize = (640, 640) # parameters from test script
|
12 |
|
13 |
if idx==0:
|
14 |
img1 = Image.new(img.mode, (height, height), (255, 255, 255))
|
15 |
img1.paste(img, ((height-width)//2, 0))
|
16 |
+
box = ( newsize[0]*(1-width/height)//2,
|
17 |
+
0,
|
18 |
+
newsize[0]-newsize[0]*(1-width/height)//2,
|
19 |
+
newsize[1])
|
20 |
else:
|
21 |
img1 = Image.new(img.mode, (width, width), (255, 255, 255))
|
22 |
+
img1.paste(img, (0, (width-height)//2))
|
23 |
+
box = (0,
|
24 |
+
newsize[1]*(1-height/width)//2,
|
25 |
+
newsize[0],
|
26 |
+
newsize[1]-newsize[1]*(1-height/width)//2)
|
27 |
im1 = img1.resize(newsize)
|
28 |
return im1,box
|
29 |
|