Calculate the entropy of an image to detect complexity.
(image)
| 498 | |
| 499 | |
| 500 | def calculate_image_entropy(image): |
| 501 | """Calculate the entropy of an image to detect complexity.""" |
| 502 | grayscale_image = image.convert('L') |
| 503 | histogram = grayscale_image.histogram() |
| 504 | hist_probabilities = [float(h) / sum(histogram) for h in histogram] |
| 505 | return -sum(p * np.log2(p) for p in hist_probabilities if p > 0) |
| 506 | |
| 507 | |
| 508 | def is_duplicate(image_bytes, hashes): |
no outgoing calls
no test coverage detected