Thomas Chardonnens commited on
Commit
f55a150
1 Parent(s): 47fc2ef

fix image processing

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -147,15 +147,18 @@ def encrypt(user_id, input_image):
147
  if input_image is None:
148
  raise gr.Error("Please choose an image first.")
149
 
150
- if input_image.shape[-1] != 3:
151
- raise ValueError(f"Input image must have 3 channels (RGB). Current shape: {input_image.shape}")
152
-
153
- # Resize the image if it hasn't the shape (224, 224, 3)
154
  if input_image.shape != (224, 224, 3):
155
  input_image_pil = Image.fromarray(input_image)
156
  input_image_pil = input_image_pil.resize((224, 224))
157
  input_image = numpy.array(input_image_pil)
158
 
 
 
 
 
 
 
 
159
  # Retrieve the client API
160
  client = get_client(user_id)
161
 
 
147
  if input_image is None:
148
  raise gr.Error("Please choose an image first.")
149
 
 
 
 
 
150
  if input_image.shape != (224, 224, 3):
151
  input_image_pil = Image.fromarray(input_image)
152
  input_image_pil = input_image_pil.resize((224, 224))
153
  input_image = numpy.array(input_image_pil)
154
 
155
+ # Convert to grayscale and reshape to (1, 1, 224, 224)
156
+ input_image = numpy.mean(input_image, axis=2).astype(numpy.int32)
157
+ input_image = input_image.reshape(1, 1, 224, 224)
158
+
159
+ # Scale values to 12-bit range (0-4095)
160
+ input_image = (input_image / 255.0 * 4095).astype(numpy.int32)
161
+
162
  # Retrieve the client API
163
  client = get_client(user_id)
164