Total Pageviews

Wednesday, September 2, 2026

📊 Histogram Specification / Matching

Match the histogram of an input image with a target image
Upload an input image and a target image.

1. Input Image

2. Target Image

3. Input Histogram

4. Target Histogram

5. Input CDF

6. Target CDF

7. Gray-Level Mapping

Input Gray Input H Input CDF Target Gray Target CDF New Map

8. New Mapped Image

9. Histogram After Mapping

10. Mapping Result

Waiting for histogram matching...

🧮 Histogram Matching Mathematics

Step 1 — Convert image to grayscale

For an RGB pixel:

Gray = 0.299R + 0.587G + 0.114B
Step 2 — Calculate histogram

For each gray level rk, count the number of pixels.

H(rk) = nk
Step 3 — Calculate probability

If N is the total number of pixels:

P(rk) = nk / N
Step 4 — Calculate input CDF
Cinput(rk) = Σ P(rj)

where j = 0 to k.

Step 5 — Calculate target CDF
Ctarget(zq) = Σ P(zj)
Step 6 — Find the matching gray level

For every input gray level, find the target gray level whose CDF is closest to the input CDF.

Find z such that Ctarget(z) ≈ Cinput(r)
Step 7 — Create the mapping
r → z

Every pixel having gray level r is replaced with the mapped gray level z.

Example
Input CDF = 0.60

Suppose the target histogram has:

Target CDF at gray 150 = 0.58 Target CDF at gray 151 = 0.61

The closest target CDF is 0.61, therefore:

Input gray level → Target gray level r → 151
Complete process
Input Image → Grayscale → Input Histogram → Input CDF → Target Histogram → Target CDF → Mapping → New Image

Histogram Equalization Visualizer

📊 Histogram Equalization Visualizer

Upload an image and explore grayscale conversion, histogram analysis, histogram equalization and its mathematics.
Please upload an image to begin.

1. Original Image

2. Grayscale Image

3. Grayscale Histogram

4. Histogram Values

Gray Level Frequency Probability CDF New Gray Level

5. Equalized Image

6. Histogram After Equalization

🧮 Histogram Equalization Mathematics

Step 1: Find the frequency

For every grayscale intensity rk, count how many pixels have that intensity.

nk = Number of pixels having intensity rk
Step 2: Calculate probability

Let n be the total number of pixels.

p(rk) = nk / n
Step 3: Calculate cumulative distribution function (CDF)
CDF(rk) = Σ p(rj)    for j = 0 to k

The CDF adds the probabilities from the first gray level up to the current gray level.

Step 4: Histogram equalization formula
sk = (L - 1) × CDF(rk)

Where:

  • L = number of possible gray levels
  • For an 8-bit image, L = 256
  • Therefore L − 1 = 255
  • rk = original gray level
  • sk = new equalized gray level
Step 5: Example calculation

Suppose an intensity level has:

CDF = 0.60

For an 8-bit image:

s = 255 × 0.60
s = 153

Therefore, the original gray level is mapped to approximately gray level 153.

Complete process
Image → Grayscale → Histogram → Probability → CDF → Mapping → Equalized Image