1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.openimaj.image.feature.dense.binarypattern;
31
32 import gnu.trove.list.array.TIntArrayList;
33
34 import org.openimaj.citation.annotation.Reference;
35 import org.openimaj.citation.annotation.ReferenceType;
36 import org.openimaj.feature.FloatFV;
37
38
39
40
41
42
43
44
45 @Reference(
46 type = ReferenceType.Article,
47 author = { "Ojala, T.", "Pietikainen, M.", "Maenpaa, T." },
48 title = "Multiresolution gray-scale and rotation invariant texture classification with local binary patterns",
49 year = "2002",
50 journal = "Pattern Analysis and Machine Intelligence, IEEE Transactions on",
51 pages = { "971 ", "987" },
52 month = "jul",
53 number = "7",
54 volume = "24",
55 customData = {
56 "doi", "10.1109/TPAMI.2002.1017623",
57 "ISSN", "0162-8828"
58 })
59 public class LocalUniformBinaryPatternHistogram {
60 protected int blocksize_x;
61 protected int blocksize_y;
62 FloatFV[][] histograms;
63
64
65
66
67
68
69
70
71
72 public LocalUniformBinaryPatternHistogram(int blocksize_x, int blocksize_y) {
73 this.blocksize_x = blocksize_x;
74 this.blocksize_y = blocksize_y;
75 }
76
77
78
79
80
81
82
83
84
85
86 public void calculateHistograms(int[][] patternImage, int nbits) {
87 final int height = patternImage.length;
88 final int width = patternImage[0].length;
89 final TIntArrayList uniformPatterns = UniformBinaryPattern.getUniformPatterns(nbits);
90
91 histograms = new FloatFV[(int) Math.ceil((double) height / (double) blocksize_y)][(int) Math.ceil((double) width
92 / (double) blocksize_x)];
93
94 for (int y = 0, j = 0; y < height; y += blocksize_y, j++) {
95 for (int x = 0, i = 0; x < width; x += blocksize_x, i++) {
96 histograms[j][i] = new FloatFV(uniformPatterns.size() + 1);
97
98 for (int yy = y; yy < Math.min(height, y + blocksize_y); yy++) {
99 for (int xx = x; xx < Math.min(width, x + blocksize_x); xx++) {
100 final int idx = uniformPatterns.indexOf(patternImage[yy][xx]);
101
102 histograms[j][i].values[idx + 1]++;
103 }
104 }
105 }
106 }
107 }
108
109
110
111
112
113
114 public FloatFV[][] getHistograms() {
115 return histograms;
116 }
117
118
119
120
121
122
123 public FloatFV getHistogram() {
124 final int len = histograms[0][0].length();
125 final FloatFV h = new FloatFV(histograms.length * histograms[0].length * len);
126
127 for (int j = 0; j < histograms.length; j++) {
128 for (int i = 0; i < histograms[0].length; i++) {
129 final int blkid = i + j * histograms[0].length;
130 System.arraycopy(histograms[j][i].values, 0, h.values, blkid * len, len);
131 }
132 }
133
134 return h;
135 }
136 }