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

No comments:

Post a Comment