Compute image complexity (for picture vs icon). Returns (laplacian_variance, std_deviation).
(image_arr: np.ndarray)
| 413 | |
| 414 | # ======================== Image complexity ======================== |
| 415 | def calculate_image_complexity(image_arr: np.ndarray) -> tuple: |
| 416 | """Compute image complexity (for picture vs icon). Returns (laplacian_variance, std_deviation).""" |
| 417 | if image_arr.size == 0: |
| 418 | return 0.0, 0.0 |
| 419 | |
| 420 | gray = cv2.cvtColor(image_arr, cv2.COLOR_BGR2GRAY) |
| 421 | |
| 422 | # Laplacian variance (texture/edge) |
| 423 | laplacian_var = cv2.Laplacian(gray, cv2.CV_64F).var() |
| 424 | |
| 425 | # Std dev (contrast/color variation) |
| 426 | std_dev = np.std(gray) |
| 427 | |
| 428 | return laplacian_var, std_dev |
| 429 | |
| 430 | |
| 431 | def is_complex_image(image_arr: np.ndarray, laplacian_threshold: float = 800, std_threshold: float = 50) -> bool: |