sigyllly commited on
Commit
00c41dd
1 Parent(s): f02dee0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -32,22 +32,26 @@ def process_image(image, prompt, threshold, alpha_value, draw_rectangles):
32
 
33
  mask = Image.fromarray(np.uint8(mat * 255), "L") # Convert to PIL Image
34
 
 
 
 
35
  # normalize the mask
36
- mask_min = mask.min()
37
- mask_max = mask.max()
38
- mask = (mask - mask_min) / (mask_max - mask_min)
39
 
40
  # threshold the mask
41
- bmask = mask > threshold
42
  # zero out values below the threshold
43
- mask[mask < threshold] = 0
44
 
45
- bmask = Image.fromarray(bmask.astype(np.uint8) * 255, "L")
46
 
47
  return bmask
48
 
49
 
50
 
 
51
  @app.route('/')
52
  def index():
53
  return "Hello, World! clipseg2"
 
32
 
33
  mask = Image.fromarray(np.uint8(mat * 255), "L") # Convert to PIL Image
34
 
35
+ # Convert the mask to a NumPy array for calculation
36
+ mask_array = np.array(mask)
37
+
38
  # normalize the mask
39
+ mask_min = mask_array.min()
40
+ mask_max = mask_array.max()
41
+ mask_array = (mask_array - mask_min) / (mask_max - mask_min)
42
 
43
  # threshold the mask
44
+ bmask = mask_array > threshold
45
  # zero out values below the threshold
46
+ mask_array[mask_array < threshold] = 0
47
 
48
+ bmask = Image.fromarray((bmask * 255).astype(np.uint8), "L")
49
 
50
  return bmask
51
 
52
 
53
 
54
+
55
  @app.route('/')
56
  def index():
57
  return "Hello, World! clipseg2"