itsyogesh commited on
Commit
2f0e3c8
·
verified ·
1 Parent(s): c09a6b8

Redesigned flow

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -183,7 +183,7 @@ hypar["model"] = ISNetDIS()
183
  # Build Model
184
  net = build_model(hypar, device)
185
 
186
-
187
  def inference(image):
188
  image_path = image
189
 
@@ -207,6 +207,40 @@ def inference(image):
207
  im_dark.putalpha(pil_processed_mask)
208
 
209
  return [cropped_signature_image, processed_mask, im_dark]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
 
211
 
212
  title = "Mysign.id - Signature Background removal based on DIS"
 
183
  # Build Model
184
  net = build_model(hypar, device)
185
 
186
+ '''
187
  def inference(image):
188
  image_path = image
189
 
 
207
  im_dark.putalpha(pil_processed_mask)
208
 
209
  return [cropped_signature_image, processed_mask, im_dark]
210
+ '''
211
+
212
+ def inference(image):
213
+ image_path = image
214
+
215
+ # Load and predict the mask for the original image
216
+ image_tensor, orig_size = load_image(image_path, hypar)
217
+ original_mask = predict(net, image_tensor, orig_size, hypar, device)
218
+
219
+ # Crop the signature from the original image
220
+ cropped_signature_image = crop_signature(image_path, original_mask, 64)
221
+
222
+ # Resize the cropped image to the expected input size for the model
223
+ resized_cropped_image = cropped_signature_image.resize(hypar["input_size"], Image.BILINEAR)
224
+
225
+ # Convert the resized cropped image to a tensor for model input
226
+ resized_cropped_image_tensor, _ = load_image(resized_cropped_image, hypar)
227
+
228
+ # Predict the mask for the resized cropped signature image
229
+ cropped_mask = predict(net, resized_cropped_image_tensor, orig_size, hypar, device)
230
+
231
+ # Convert the refined cropped mask to a PIL image
232
+ pil_cropped_mask = Image.fromarray(cropped_mask).convert('L')
233
+
234
+ # Apply the refined mask to the resized cropped signature image
235
+ im_rgba_cropped = resized_cropped_image.copy()
236
+ im_rgba_cropped.putalpha(pil_cropped_mask)
237
+
238
+ # Create a dark image with the same size as the resized cropped signature image
239
+ im_dark_cropped = Image.new('RGB', im_rgba_cropped.size, (0, 0, 0))
240
+ im_dark_cropped.putalpha(pil_cropped_mask)
241
+
242
+ # The outputs are now based on the resized cropped image
243
+ return [im_rgba_cropped, pil_cropped_mask, im_dark_cropped]
244
 
245
 
246
  title = "Mysign.id - Signature Background removal based on DIS"