{
  "id": "enwiki-001376341283",
  "slug": "histogram-equalization",
  "title": "Histogram equalization",
  "qid": "",
  "lead": "In image processing, Histogram equalization is a method of contrast adjustment using the image's histogram. Histogram equalization is a specific case of the more general class of histogram remapping methods. These methods seek to adjust the image to make it easier to analyze or improve visual quality.",
  "body": "In image processing, Histogram equalization is a method of contrast adjustment using the image's histogram. Histogram equalization is a specific case of the more general class of histogram remapping methods. These methods seek to adjust the image to make it easier to analyze or improve visual quality. ==Overview== This method usually increases the global contrast of many images, especially when the image is represented by a narrow range of intensity values. Through this adjustment, the intensities can be better distributed on the histogram, utilizing the full range of intensities evenly. This allows for areas of lower local contrast to gain higher contrast. Histogram equalization accomplishes this by effectively spreading out the highly populated intensity values, which tend to degrade image contrast. The method is useful in images with backgrounds and foregrounds that are both bright or both dark. In particular, the method can lead to better views of bone structure in x-ray images and to better detail in photographs that are either over- or under-exposed. A key advantage of the method is that it is a fairly straightforward technique, adaptive to the input image and an invertible operation. So, in theory, if the histogram equalization function is known, then the original histogram can be recovered. The calculation is not computationally intensive. A disadvantage of the method is that it is indiscriminate. It may increase the contrast of background noise, while decreasing the usable signal. In scientific imaging, where spatial correlation is more important than intensity of signal (such as separating DNA fragments of quantized length), the small signal-to-noise ratio usually hampers visual detections. Histogram equalization often produces unrealistic effects in photographs; however, it is very useful for scientific images like thermal, satellite or x-ray images, often the same class of images to which one would apply false-color. Also, histogram equalization can produce undesirable effects (like visible image gradient) when applied to images with low color depth. For example, if applied to an 8-bit image displayed with 8-bit gray-scale palette it will further reduce color depth (number of unique shades of gray) of the image. Histogram equalization will work best when applied to images with much higher color depth than palette size, like continuous data or 16-bit gray-scale images. There are two ways to think about and implement histogram equalization, either as an image change or as a palette change. The operation can be expressed as P(M( I )) where I is the original image, M is the histogram equalization mapping operation, and P is a palette. If we define a new palette as P' = P(M) and leave image I unchanged, then histogram equalization is implemented as palette change or mapping change. On the other hand, if palette P remains unchanged and the image is modified to I ' = M(I) then the implementation is accomplished by image change. In most cases, palette change is preferred as it preserves the original data. Modifications of this method use multiple histograms, called subhistograms, to emphasize local contrast rather than overall global contrast. Examples of such methods include adaptive histogram equalization and variations including contrast-limited adaptive histogram equalization, multipeak histogram equalization, and multipurpose beta-optimized bihistogram equalization (MBOBHE). The goal of these methods, especially MBOBHE, is to modify the algorithm to improve the contrast without producing brightness mean-shift and detail loss artifacts. A signal transform equivalent to histogram equalization also seems to happen in biological neural networks so as to maximize the output firing rate of the neuron as a function of the input statistics. This has been proved in particular in the fly retina. ===Back projection=== The back projection of a histogrammed image is the re-application of the modified histogram to the original image, functioning as a look-up table for pixel brightness values. For each group of pixels taken from the same position from all input single-channel images, the function puts the histogram bin value to the destination image, where the coordinates of the bin are determined by the values of pixels in this input group. In terms of statistics, the value of each output image pixel characterizes the probability that the corresponding input pixel group belongs to the object whose histogram is used. ==Implementation== Consider a discrete grayscale image X and let n_i be the number of occurrences of gray level i . The probability of a pixel value chosen uniformly randomly from image X being i , is \\ p_X(i) = \\frac{n_i}{n},\\quad 0 \\le i L being the total number of gray levels in the image, n_i being the number of pixels in the image with value i , and n being the total number of pixels in the image. Then p_X(i) is the image's histogram value for i , with the histogram normalized to have a total area of 1. Let us then define the cumulative distribution function of pixels in image X . For value i it is \\operatorname{cdf}_X(i) = \\sum_{j=0}^i p_X(j) , which is also the image's accumulated normalized histogram. We would like to create a transformation T:[0,L-1] \\rightarrow [0,L-1] to produce a new image Y , with a flat histogram. Such an image would have a linearized cumulative distribution function (CDF) across the value range, i.e. \\operatorname{cdf}_Y(i) = (i+1) K for 0 \\le i for some constant K . The properties of the CDF allow us to perform such a transform (see Inverse distribution function). It is defined as \\ T(i) = \\operatorname{cdf}_X(i) where \\ i is in the range [0,L-1] . Notice that \\ T maps the levels into the range [0,1] , since we used a normalized histogram of X . In order to map the values back into their original range, the following simple transformation needs to be applied to each transformed image value k : \\ k^\\prime = k \\cdot(\\max(i) - \\min(i)) + \\min(i)= k \\cdot(L- 1) k is a real value while \\ k^\\prime has to be an integer. An intuitive and popular method is applying the round operation: \\ k^\\prime = \\operatorname{round} (k \\cdot(L- 1)) . However, detailed analysis results in a slightly different formulation. The mapped value k^\\prime should be 0 for the range of 0 . And k^\\prime =1 for 1/L , k^\\prime = 2 for 2/L , ...., and finally k^\\prime =L-1 for (L-1)/L . Then the quantization formula from k to k^\\prime should be k^\\prime=\\operatorname{ceil}(L \\cdot k)-1 . (Note: k^\\prime=-1 when k=0 , however, it does not happen just because k=0 means that there is no pixel corresponding to that value.) ==Examples== The operation equalization process is best demonstrated with a small image. A full-sized image demonstrates the overall results achievable using the process. ===Small image=== The 8-bit grayscale image shown has the following values: The histogram for this image is shown in the following table. Pixel values that have a zero count are excluded for the sake of brevity. The cumulative distribution function (CDF) is shown below. Again, pixel values that do not contribute to an increase in the function are excluded for brevity. (Please note that h(v)=\\operatorname{ceil}(\\operatorname{CDF}(v))-1 version is not illustrated yet.) This CDF shows that the minimum value in the subimage is 52 and the maximum value is 154. The CDF of 64 for value 154 coincides with the number of pixels in the image. The CDF must be normalized to [0,255] . The general histogram equalization formula is: h(v) = \\mathrm{round} \\left( \\frac {\\operatorname{CDF}(v) - \\operatorname{CDF}_{\\min}} {(M \\times N) - \\operatorname{CDF}_{\\min}} \\times (L - 1) \\right) where \\operatorname{CDF}_{\\min} is the minimum non-zero value of the cumulative distribution function (in this case 1), M \\times N gives the image's number of pixels (for the example above 64, where M is width and N the height) and L is the number of grey levels used (in most cases, like this one, 256). Note that to scale values in the original data that are above 0 to the range 1 to L-1 , inclusive, the above equation would instead be: h(v) = \\mathrm{round} \\left( \\frac {\\operatorname{CDF}(v) - \\operatorname{CDF}_{\\min}} {(M \\times N) - \\operatorname{CDF}_{\\min}} \\times (L - 2) \\right) + 1 where cdf(v) > 0. Scaling from 1 to 255 preserves the non-zero-ness of the minimum value. The equalization formula for the example scaling data from 0 to 255, inclusive, is: h(v) = \\mathrm{round} \\left( \\frac {\\operatorname{cdf}(v) - 1} {63} \\times 255 \\right) For example, the CDF of 78 is 46. (The value of 78 is used in the bottom row of the 7th column.) The normalized value becomes: h(78) = \\mathrm{round} \\left( \\frac {46 - 1} {63} \\times 255 \\right) = \\mathrm{round} \\left( 0.714286 \\times 255 \\right) = 182 Once this is done, then the values of the equalized image are directly taken from the normalized CDF to yield the equalized values: Notice that the minimum value 52 is now 0 and the maximum value 154 is now 255. ===Full-sized image=== Note that in the above graphs, the cumulative histogram's vertical axis scale is different from that of the histogram. If we were to draw them both to the same scale, the cumulative histogram would go much higher than the histogram. This is because the histogram shows the number of pixels having a certain value, while the cumulative histogram counts the total number of pixels equal to or below the given value. Hence, the cumulative histogram at the highest value must equal the total number of pixels composing the image. Also, the scale of the vertical axis of the unequalized image's histogram is different from that of the equalized image's histogram. If both histograms were drawn to the same scale, the equalized image's histogram bars would be of lower height than those of the unequalized image.",
  "categories": [
    "102876480",
    "11060667",
    "22907083",
    "22908952",
    "22915279",
    "22922474",
    "22961512",
    "23603337",
    "24623845",
    "26220375",
    "29379983",
    "48128016",
    "48994736",
    "68328988"
  ],
  "license": "CC BY-SA 4.0",
  "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1376341283",
  "content_hash": "",
  "created_at": null,
  "updated_at": 1790170184.0,
  "claims": [],
  "contradictions": [],
  "confidence": 0.6,
  "csl": {
    "id": "enwiki-001376341283",
    "type": "webpage",
    "title": "Histogram equalization",
    "author": [
      {
        "family": "Anticloud FZ LLE",
        "literal": "Anticloud FZ LLE"
      }
    ],
    "container-title": "encyclopegia.org",
    "publisher": "Anticloud FZ LLE",
    "publisher-place": "Dubai, United Arab Emirates",
    "URL": "https://encyclopegia.org/a/histogram-equalization",
    "issued": {
      "date-parts": [
        [
          2026,
          11,
          20
        ]
      ]
    },
    "accessed": {
      "date-parts": [
        [
          2026,
          11,
          20
        ]
      ]
    },
    "license": "CC BY-SA 4.0",
    "DOI": "eo1:enwiki-001376341283",
    "isBasedOn": "https://en.wikipedia.org/w/index.php?oldid=1376341283",
    "note": "Immutable snapshot enwiki-001376341283"
  }
}