Stable-X commited on
Commit
3e3116b
1 Parent(s): e9293a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -65,17 +65,31 @@ def process_image_check(path_input):
65
  )
66
 
67
  def resize_image(input_image, resolution):
68
- input_image = np.asarray(input_image)
69
- H, W, C = input_image.shape
 
 
 
 
 
 
 
70
  H = float(H)
71
  W = float(W)
 
 
72
  k = float(resolution) / min(H, W)
 
 
73
  H *= k
74
  W *= k
75
  H = int(np.round(H / 64.0)) * 64
76
  W = int(np.round(W / 64.0)) * 64
77
- img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)
78
- return Image.fromarray(img)
 
 
 
79
 
80
  def process_image(
81
  pipe,
 
65
  )
66
 
67
  def resize_image(input_image, resolution):
68
+ # Ensure input_image is a PIL Image object
69
+ if not isinstance(input_image, Image.Image):
70
+ raise ValueError("input_image should be a PIL Image object")
71
+
72
+ # Convert image to numpy array
73
+ input_image_np = np.asarray(input_image)
74
+
75
+ # Get image dimensions
76
+ H, W, C = input_image_np.shape
77
  H = float(H)
78
  W = float(W)
79
+
80
+ # Calculate the scaling factor
81
  k = float(resolution) / min(H, W)
82
+
83
+ # Determine new dimensions
84
  H *= k
85
  W *= k
86
  H = int(np.round(H / 64.0)) * 64
87
  W = int(np.round(W / 64.0)) * 64
88
+
89
+ # Resize the image using PIL's resize method
90
+ img = input_image.resize((W, H), Image.LANCZOS if k > 1 else Image.ANTIALIAS)
91
+
92
+ return img
93
 
94
  def process_image(
95
  pipe,