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.global;
31
32 import org.openimaj.citation.annotation.Reference;
33 import org.openimaj.citation.annotation.ReferenceType;
34 import org.openimaj.feature.DoubleFV;
35 import org.openimaj.feature.FeatureVectorProvider;
36 import org.openimaj.image.FImage;
37 import org.openimaj.image.analyser.ImageAnalyser;
38 import org.openimaj.image.processor.GridProcessor;
39 import org.openimaj.math.util.FloatArrayStatsUtils;
40
41
42
43
44
45
46
47 @Reference(
48 type = ReferenceType.Inproceedings,
49 author = { "Che-Hua Yeh", "Yuan-Chen Ho", "Brian A. Barsky", "Ming Ouhyoung" },
50 title = "Personalized Photograph Ranking and Selection System",
51 year = "2010",
52 booktitle = "Proceedings of ACM Multimedia",
53 pages = { "211", "220" },
54 month = "October",
55 customData = { "location", "Florence, Italy" })
56 public class YehBokehEstimator implements ImageAnalyser<FImage>, FeatureVectorProvider<DoubleFV> {
57 class Sharpness implements GridProcessor<Float, FImage> {
58 SharpPixelProportion bpp = new SharpPixelProportion();
59
60 @Override
61 public int getHorizontalGridElements() {
62 return nBlocksX;
63 }
64
65 @Override
66 public int getVerticalGridElements() {
67 return nBlocksY;
68 }
69
70 @Override
71 public Float processGridElement(FImage patch) {
72 patch.analyseWith(bpp);
73 return (float) bpp.getBlurredPixelProportion();
74 }
75 }
76
77 class GreyLevelVariance implements GridProcessor<Float, FImage> {
78 @Override
79 public int getHorizontalGridElements() {
80 return nBlocksX;
81 }
82
83 @Override
84 public int getVerticalGridElements() {
85 return nBlocksY;
86 }
87
88 @Override
89 public Float processGridElement(FImage patch) {
90 return FloatArrayStatsUtils.var(patch.pixels);
91 }
92 }
93
94 Sharpness sharpProcessor = new Sharpness();
95 GreyLevelVariance varProcessor = new GreyLevelVariance();
96
97 int nBlocksX = 5;
98 int nBlocksY = 5;
99
100 float varThreshold = 0.1f;
101 float sharpnessThreshold = 0.5f;
102 float lowerBound = 0.3f;
103 float upperBound = 0.7f;
104
105 double bokeh;
106
107
108
109
110
111 public YehBokehEstimator() {
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 public YehBokehEstimator(int nBlocksX, int nBlocksY, float varThreshold, float sharpnessThreshold, float lowerBound,
131 float upperBound)
132 {
133 this.nBlocksX = nBlocksX;
134 this.nBlocksY = nBlocksY;
135 this.varThreshold = varThreshold;
136 this.sharpnessThreshold = sharpnessThreshold;
137 this.lowerBound = lowerBound;
138 this.upperBound = upperBound;
139 }
140
141 @Override
142 public DoubleFV getFeatureVector() {
143 return new DoubleFV(new double[] { bokeh });
144 }
145
146
147
148
149
150
151
152
153 @Override
154 public void analyseImage(FImage image) {
155 final FImage sharpness = image.process(sharpProcessor);
156 final FImage variance = image.process(varProcessor);
157
158 double Qbokeh = 0;
159 int validBlocks = 0;
160 for (int y = 0; y < sharpness.height; y++) {
161 for (int x = 0; x < sharpness.width; x++) {
162 if (variance.pixels[y][x] >= varThreshold) {
163 Qbokeh += sharpness.pixels[y][x] > 0.5 ? 1 : 0;
164 validBlocks++;
165 }
166 }
167 }
168 Qbokeh /= (validBlocks);
169
170 bokeh = (Qbokeh >= lowerBound && Qbokeh <= upperBound) ? 1 : 0;
171 }
172 }