nermadie/2.5D_Depth_Studio
0
1"""2Configuration file for the Facebook 3D Photo Effect.3Tune parameters here instead of editing the code.4"""5 6# ============================================================================7# DEPTH ESTIMATION SETTINGS8# ============================================================================9 10DEPTH_CONFIG = {11 # Model to use - try in order of preference12 "models": [13 "Intel/dpt-large", # Best quality, slower (recommended)14 "Intel/dpt-hybrid-midas", # Good balance15 ],16 # Pre-processing17 "resize_max": 1024, # Max dimension (higher = better quality but slower)18 "apply_clahe": True, # Contrast enhancement19 "denoise": False, # Denoise input (might blur details)20 # Post-processing depth map21 "bilateral_filter": {22 "enabled": True,23 "d": 9, # Filter size24 "sigma_color": 75,25 "sigma_space": 75,26 },27 "edge_preserving": {28 "enabled": True,29 "sigma_s": 60,30 "sigma_r": 0.4,31 },32 "morphology": {33 "enabled": True,34 "kernel_size": 5,35 "iterations": 1,36 },37}38 39# ============================================================================40# LAYER SEPARATION SETTINGS41# ============================================================================42 43LAYER_CONFIG = {44 # Number of layers to create45 "num_layers": 4, # 4 = backplate + bg + mg + fg46 # Depth percentiles for layer boundaries47 # Adjust these based on your images48 "percentiles": {49 "foreground": 70, # Above this = foreground (70-100)50 "midground": 40, # Middle range (40-70)51 "background": 10, # Below midground (10-40)52 # Below 10 = backplate53 },54 # Morphology for mask cleaning55 "morphology": {56 "close_kernel": 7,57 "close_iterations": 2,58 "open_kernel": 7,59 "open_iterations": 1,60 },61 # Soft mask settings62 "soft_mask": {63 "blur_sigma": {64 "foreground": 12, # Less blur = sharper edges65 "midground": 14,66 "background": 16, # More blur = softer edges67 },68 "power_curve": 0.8, # < 1.0 = softer, > 1.0 = harder69 },70}71 72# ============================================================================73# INPAINTING SETTINGS74# ============================================================================75 76INPAINT_CONFIG = {77 # Inpainting method78 "method": "TELEA", # TELEA or NS (TELEA recommended)79 # Mask dilation before inpainting80 "mask_dilate": {81 "kernel_size": 11,82 "iterations": 3,83 },84 # Inpaint radius85 "radius": 5, # Larger = more context used86 # Post-inpaint blur to smooth artifacts87 "post_blur": {88 "foreground": 0, # No blur89 "midground": (3, 3), # Slight blur90 "background": (5, 5), # More blur for depth effect91 "backplate": (7, 7), # Most blur92 },93 "post_blur_sigma": {94 "foreground": 0,95 "midground": 0.5,96 "background": 1.0,97 "backplate": 1.5,98 },99}100 101# ============================================================================102# FRONTEND ANIMATION SETTINGS103# ============================================================================104 105ANIMATION_CONFIG = {106 # Parallax effect strength107 "parallax_strength": 30, # 0-100, higher = more movement108 # 3D rotation amount109 "rotation_amount": 4, # Degrees, higher = more tilt110 # Animation smoothness111 "smoothness": 0.12, # 0.01-0.3, lower = more responsive112 # Z-axis depth scale113 "depth_scale": 50, # Higher = more 3D depth114 # Layer scaling115 "layer_scale": 1.08, # Closer layers slightly bigger116 # Opacity variation117 "opacity_variation": True, # Slight opacity change based on depth118 # Performance119 "use_3d_transforms": True, # Hardware acceleration120 "max_fps": 60, # Cap FPS for performance121}122 123# ============================================================================124# QUALITY PRESETS125# ============================================================================126 127PRESETS = {128 "mobile": {129 "resize_max": 640,130 "model_index": 1, # hybrid-midas131 "num_layers": 3,132 "inpaint_radius": 3,133 "parallax_strength": 20,134 },135 "balanced": {136 "resize_max": 1024,137 "model_index": 0, # dpt-large138 "num_layers": 4,139 "inpaint_radius": 5,140 "parallax_strength": 30,141 },142 "quality": {143 "resize_max": 1920,144 "model_index": 0, # dpt-large145 "num_layers": 4,146 "inpaint_radius": 7,147 "parallax_strength": 35,148 },149}150 151# ============================================================================152# DEBUGGING153# ============================================================================154 155DEBUG_CONFIG = {156 "save_intermediate": False, # Save depth maps, masks, etc.157 "output_dir": "./debug",158 "verbose": True,159 "show_processing_time": True,160}161 162# ============================================================================163# HELPER FUNCTIONS164# ============================================================================165 166 167def load_preset(preset_name="balanced"):168 """Load a quality preset"""169 if preset_name not in PRESETS:170 raise ValueError(171 f"Unknown preset: {preset_name}. Available: {list(PRESETS.keys())}"172 )173 174 preset = PRESETS[preset_name]175 176 # Apply preset to configs177 DEPTH_CONFIG["resize_max"] = preset["resize_max"]178 LAYER_CONFIG["num_layers"] = preset["num_layers"]179 INPAINT_CONFIG["radius"] = preset["inpaint_radius"]180 ANIMATION_CONFIG["parallax_strength"] = preset["parallax_strength"]181 182 return preset183 184 185def get_config_summary():186 """Print current configuration"""187 return f"""188Current Configuration:189=====================190Depth Model: {DEPTH_CONFIG['models'][0]}191Max Size: {DEPTH_CONFIG['resize_max']}px192Layers: {LAYER_CONFIG['num_layers']}193Inpaint Radius: {INPAINT_CONFIG['radius']}194Parallax Strength: {ANIMATION_CONFIG['parallax_strength']}195Smoothness: {ANIMATION_CONFIG['smoothness']}196"""197 198 199# ============================================================================200# USAGE EXAMPLES201# ============================================================================202 203"""204# In main_improved.py, import config:205from config import DEPTH_CONFIG, LAYER_CONFIG, INPAINT_CONFIG206 207# Use values:208max_size = DEPTH_CONFIG['resize_max']209num_layers = LAYER_CONFIG['num_layers']210 211# Load preset:212from config import load_preset213load_preset("quality") # or "mobile" or "balanced"214 215# Print config:216from config import get_config_summary217print(get_config_summary())218"""219 