图像熵的定义、数学计算方法及图像间熵差异原因
Great question—image entropy is a core metric for quantifying how much "randomness" or information is packed into an image's pixel data. Let's break this down into two clear parts: how to calculate it mathematically, and why different images end up with different entropy values.
Mathematical Calculation of Image Entropy
Image entropy draws directly from Claude Shannon's information theory. Here's the straightforward step-by-step process:
- Count pixel value frequencies: First, tally how many times each distinct pixel value (usually grayscale intensity, but this works for RGB channels too) appears in the image. For an 8-bit grayscale image, that’s values ranging from 0 (pure black) to 255 (pure white).
- Convert to probabilities: Turn each frequency into a probability
p_iby dividing the count of the i-th pixel value by the total number of pixels in the image. So:p_i = (number of pixels with value i) / (total number of pixels) - Apply the entropy formula: Use Shannon’s entropy equation, which sums the weighted logarithm of each probability (we use base-2 log because we measure information in bits):
H = -Σ (p_i * log₂(p_i))Note: If a pixel value never appears (
p_i = 0), we skip that term entirely—since0 * log₂(0)is undefined and contributes nothing to the total entropy.
Quick Practical Example
- A solid black image (all pixels = 0): Only one non-zero probability
p_0 = 1, soH = -(1 * log₂(1)) = 0(no randomness, no new information). - A perfectly balanced 8-bit image (50% black, 50% white):
p_0 = 0.5,p_255 = 0.5, soH = -(0.5*log₂(0.5) + 0.5*log₂(0.5)) = 1bit per pixel.
Why Image Entropy Values Differ
Entropy varies drastically between images because it directly reflects the diversity and distribution of pixel values. Here are the key factors driving these differences:
- Content complexity: Images with rich textures, fine details, or mixed color palettes (like a busy city street or dense forest) have higher entropy—there are many distinct pixel values spread evenly across the image. A solid color background or simple line drawing has very low entropy.
- Bit depth/color range: The maximum possible entropy depends on the number of possible pixel values. An 8-bit grayscale image (256 values) can hit a max entropy of ~8 bits per pixel (if all values are equally likely), while a 1-bit binary image only maxes out at 1 bit per pixel.
- Noise presence: Random noise (like grain in low-light photos) adds unexpected pixel values, increasing the diversity of the pixel distribution—so noisy images have higher entropy than clean versions of the same scene.
- Compression effects: Lossless compression cuts down on redundant pixel data, which lowers entropy (since compressed data has less randomness). Lossy compression goes further by discarding non-critical information, also reducing entropy.
- Scene uniformity: Images with large uniform areas (like a clear blue sky or blank document) have lower entropy because most pixels fall into a small range of values. Images with no large uniform patches (like a mosaic or confetti) have higher entropy.
内容的提问来源于stack exchange,提问作者gag123




