mac9087 commited on
Commit
af0c60f
·
verified ·
1 Parent(s): afec0dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -53
app.py CHANGED
@@ -455,60 +455,9 @@ def depth_to_mesh(depth_map, image, resolution=100, detail_level='medium'):
455
  mesh.fix_normals()
456
 
457
  return mesh
458
-
459
- # Enhanced image preprocessing to properly handle PNGs with transparency
460
- def preprocess_image(image_path):
461
- with Image.open(image_path) as img:
462
- # Get original mode to check if it has transparency
463
- original_mode = img.mode
464
 
465
- # Convert to RGB or RGBA as needed
466
- if original_mode == 'RGBA':
467
- # Keep alpha channel for transparency
468
- img = img.convert("RGBA")
469
- else:
470
- # Otherwise use RGB
471
- img = img.convert("RGB")
472
-
473
- # Resize if the image is too large
474
- if img.width > MAX_DIMENSION or img.height > MAX_DIMENSION:
475
- # Calculate new dimensions while preserving aspect ratio
476
- if img.width > img.height:
477
- new_width = MAX_DIMENSION
478
- new_height = int(img.height * (MAX_DIMENSION / img.width))
479
- else:
480
- new_height = MAX_DIMENSION
481
- new_width = int(img.width * (MAX_DIMENSION / img.height))
482
-
483
- # Use high-quality Lanczos resampling for better detail preservation
484
- img = img.resize((new_width, new_height), Image.LANCZOS)
485
-
486
- # Handle enhancement only for RGB (non-transparent) parts
487
- if original_mode != 'RGBA':
488
- # Convert to numpy array for additional preprocessing
489
- img_array = np.array(img)
490
-
491
- # Optional: Apply adaptive histogram equalization for better contrast
492
- # This helps the depth model detect more details
493
- if len(img_array.shape) == 3 and img_array.shape[2] == 3:
494
- # Convert to LAB color space
495
- lab = cv2.cvtColor(img_array, cv2.COLOR_RGB2LAB)
496
- l, a, b = cv2.split(lab)
497
-
498
- # Apply CLAHE to L channel
499
- clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
500
- cl = clahe.apply(l)
501
-
502
- # Merge channels back
503
- enhanced_lab = cv2.merge((cl, a, b))
504
-
505
- # Convert back to RGB
506
- img_array = cv2.cvtColor(enhanced_lab, cv2.COLOR_LAB2RGB)
507
-
508
- # Convert back to PIL Image
509
- img = Image.fromarray(img_array)
510
-
511
- return img
512
 
513
  @app.route('/health', methods=['GET'])
514
  def health_check():
 
455
  mesh.fix_normals()
456
 
457
  return mesh
458
+
459
+
 
 
 
 
460
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
 
462
  @app.route('/health', methods=['GET'])
463
  def health_check():