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.processing.algorithm;
31
32 import org.openimaj.citation.annotation.Reference;
33 import org.openimaj.citation.annotation.ReferenceType;
34 import org.openimaj.image.FImage;
35 import org.openimaj.image.mask.AbstractMaskedObject;
36 import org.openimaj.image.processor.ImageProcessor;
37
38
39
40
41
42
43
44 @Reference(
45 type = ReferenceType.Article,
46 author = { "Tan, Xiaoyang", "Triggs, Bill" },
47 title = "Enhanced local texture feature sets for face recognition under difficult lighting conditions",
48 year = "2010",
49 journal = "Trans. Img. Proc.",
50 pages = { "1635", "", "1650" },
51 url = "http://dx.doi.org/10.1109/TIP.2010.2042645",
52 month = "June",
53 number = "6",
54 publisher = "IEEE Press",
55 volume = "19"
56 )
57 public class MaskedRobustContrastEqualisation extends AbstractMaskedObject<FImage> implements ImageProcessor<FImage> {
58 double alpha = 0.1;
59 double tau = 10;
60
61
62
63
64 public MaskedRobustContrastEqualisation() {
65 super();
66 }
67
68
69
70
71
72 public MaskedRobustContrastEqualisation(FImage mask) {
73 super(mask);
74 }
75
76 @Override
77 public void processImage(FImage image) {
78
79 image.divideInplace(firstPassDivisor(image, mask));
80
81
82 image.divideInplace(secondPassDivisor(image, mask));
83
84
85 for (int y=0; y<image.height; y++) {
86 for (int x=0; x<image.width; x++) {
87 if (mask.pixels[y][x] == 1) {
88 image.pixels[y][x] = (float) (tau * Math.tanh(image.pixels[y][x] / tau));
89 } else {
90 image.pixels[y][x] = 0;
91 }
92 }
93 }
94 }
95
96 float firstPassDivisor(FImage image, FImage mask) {
97 double accum = 0;
98 int count = 0;
99
100 for (int y=0; y<image.height; y++) {
101 for (int x=0; x<image.width; x++) {
102 if (mask.pixels[y][x] == 1) {
103 double ixy = image.pixels[y][x];
104
105 accum += Math.pow(Math.abs(ixy), alpha);
106 count++;
107 }
108 }
109 }
110
111 return (float) Math.pow(accum / count, 1.0 / alpha);
112 }
113
114 float secondPassDivisor(FImage image, FImage mask) {
115 double accum = 0;
116 int count = 0;
117
118 for (int y=0; y<image.height; y++) {
119 for (int x=0; x<image.width; x++) {
120 if (mask.pixels[y][x] == 1) {
121 double ixy = image.pixels[y][x];
122
123 accum += Math.pow(Math.min(tau, Math.abs(ixy)), alpha);
124 count++;
125 }
126 }
127 }
128
129 return (float) Math.pow(accum / count, 1.0 / alpha);
130 }
131 }