Digital Signal Processing Reference
In-Depth Information
11.4 Eigenschaften binarer
Bildregionen
1 import ij.process.ImageProcessor;
2
3 public class Moments {
4
Programm 11.3
Beispiel fur die direkte Berechnung
vonMomenteninJava.DieMetho-
den moment() , centralMoment() und
normalCentralMoment() berechnen
fur ein Binarbild die Momente m pq ,
µ pq bzw. µ pq (Gl. 11.15, 11.20, 11.22).
static final int BACKGROUND = 0;
5
6
static double moment(ImageProcessor ip,int p,int q) {
double Mpq = 0.0;
7
for (int v = 0; v < ip.getHeight(); v++) {
8
for (int u = 0; u < ip.getWidth(); u++) {
9
if (ip.getPixel(u,v) != BACKGROUND) {
10
Mpq += Math.pow(u, p) * Math.pow(v, q);
11
}
12
}
13
}
14
return Mpq;
15
}
16
static double centralMoment(ImageProcessor ip,int p,int q)
17
{
18
double m00 = moment(ip, 0, 0); // region area
19
double xCtr = moment(ip, 1, 0) / m00;
20
double yCtr = moment(ip, 0, 1) / m00;
21
double cMpq = 0.0;
22
for (int v = 0; v < ip.getHeight(); v++) {
23
for (int u = 0; u < ip.getWidth(); u++) {
24
if (ip.getPixel(u,v) != BACKGROUND) {
25
cMpq +=
26
Math.pow(u - xCtr, p) *
27
Math.pow(v - yCtr, q);
28
}
29
}
30
}
31
return cMpq;
32
}
33
static double normalCentralMoment
34
(ImageProcessor ip,int p,int q) {
35
double m00 = moment(ip, 0, 0);
36
double norm = Math.pow(m00, (double)(p + q + 2) / 2);
37
return centralMoment(ip, p, q) / norm;
38
}
39
40 }
Search WWH ::




Custom Search