zouzx commited on
Commit
c52acae
1 Parent(s): 37f1879

resize image

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -71,13 +71,21 @@ def assert_input_image(input_image):
71
  if input_image is None:
72
  raise gr.Error("No image selected or uploaded!")
73
 
 
 
 
 
 
 
 
74
  def preprocess(input_raw, save_path):
75
  # if not preprocess:
76
  # print("No preprocess")
77
  # # return image_path
78
 
79
  # input_raw = Image.open(image_path)
80
- input_raw.thumbnail([512, 512], Image.Resampling.LANCZOS)
 
81
  print("image size:", input_raw.size)
82
  image_sam = sam_out_nosave(
83
  sam_predictor, input_raw.convert("RGB"), pred_bbox(input_raw)
 
71
  if input_image is None:
72
  raise gr.Error("No image selected or uploaded!")
73
 
74
+ def resize_image(input_raw, size):
75
+ w, h = input_raw.size
76
+ ratio = size / max(w, h)
77
+ resized_w = int(w * ratio)
78
+ resized_h = int(h * ratio)
79
+ return input_raw.resize((resized_w, resized_h), Image.Resampling.LANCZOS)
80
+
81
  def preprocess(input_raw, save_path):
82
  # if not preprocess:
83
  # print("No preprocess")
84
  # # return image_path
85
 
86
  # input_raw = Image.open(image_path)
87
+ # input_raw.thumbnail([512, 512], Image.Resampling.LANCZOS)
88
+ input_raw = resize_image(input_raw, 512)
89
  print("image size:", input_raw.size)
90
  image_sam = sam_out_nosave(
91
  sam_predictor, input_raw.convert("RGB"), pred_bbox(input_raw)