Digital Signal Processing Reference
In-Depth Information
5.5 Histogrammanpassung
int[] matchHistograms (int[] hA, int[] hR) {
1
// hA ...original histogram h A of some image I A
2
Programm 5.3
Histogrammanpassung nach Alg. 5.1
(Java-Implementierung). Die Methode
matchHistograms() berechnet aus
dem Histogramm Ha und dem Refe-
renzhistogramm Hr die Abbildung F
(Gl. 5.24). Die in Zeile 7 verwendete
Methode Cdf() zur Berechnung der
kumulierten Verteilungsfunktion (Gl.
5.15) ist im unteren Abschnitt aus-
gefuhrt.
// hR ...reference histogram h R
3
// returns the mapping function F () to be applied to image I A
4
5
6
int K = hA.length;
// get CDF of histogram h A
double[] PA = Cdf(hA);
7
// get CDF of histogram h R
double[] PR = Cdf(hR);
8
// pixel mapping function f hs ()
int[] F = new int[K];
9
10
11
// compute mapping function f hs () :
for (int a = 0; a < K; a++) {
12
int j = K-1;
13
do {
14
F[a] = j;
15
j--;
16
} while (j>=0 && PA[a]<=PR[j]);
17
}
18
return F;
19
}
20
double[] Cdf (int[] h) {
21
// returns the cumul. distribution function for histogram h
22
int K = h.length;
23
24
25
int n = 0;
// sum all histogram values
for (int i=0; i<K; i++) {
26
n += h[i];
27
}
28
29
30
// create CDF table P
double[] P = new double[K];
// cumulate histogram values
int c = h[0];
31
P[0] = (double) c / n;
32
for (int i=1; i<K; i++) {
33
c += h[i];
34
P[i] = (double) c / n;
35
}
36
return P;
37
}
38
k =0
1
2
3
4
i k =
0
28
75
150
210
q k =
0.002
0.050
0.250
0.750
0.950
definiert (vgl. Abb. 5.12). Das zugehorige Referenzhistogramm (Abb.
5.14 (c)) ist stufenformig, wobei die linearen Segmente in der Vertei-
lungsfunktion den konstanten Abschnitten in der Wahrscheinlichkeits-
dichtefunktion bzw. im Histogramm entsprechen. Die Verteilungsfunk-
tion des angepassten Bilds (Abb. 5.14 (h)) stimmt weitgehend mit der
Search WWH ::




Custom Search