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 gnu.trove.map.hash.TObjectFloatHashMap;
33 import gnu.trove.procedure.TObjectFloatProcedure;
34
35 import org.openimaj.citation.annotation.Reference;
36 import org.openimaj.citation.annotation.ReferenceType;
37 import org.openimaj.feature.DoubleFV;
38 import org.openimaj.feature.FeatureVectorProvider;
39 import org.openimaj.image.FImage;
40 import org.openimaj.image.MBFImage;
41 import org.openimaj.image.analyser.ImageAnalyser;
42 import org.openimaj.image.pixel.ConnectedComponent;
43 import org.openimaj.image.processor.connectedcomponent.render.BoundingBoxRenderer;
44 import org.openimaj.image.saliency.AchantaSaliency;
45 import org.openimaj.image.saliency.YehSaliency;
46 import org.openimaj.image.segmentation.FelzenszwalbHuttenlocherSegmenter;
47 import org.openimaj.util.array.ArrayUtils;
48
49
50
51
52
53
54
55
56
57
58 @Reference(
59 type = ReferenceType.Inproceedings,
60 author = { "Che-Hua Yeh", "Yuan-Chen Ho", "Brian A. Barsky", "Ming Ouhyoung" },
61 title = "Personalized Photograph Ranking and Selection System",
62 year = "2010",
63 booktitle = "Proceedings of ACM Multimedia",
64 pages = { "211", "220" },
65 month = "October",
66 customData = { "location", "Florence, Italy" })
67 public class ROIProportion implements ImageAnalyser<MBFImage>, FeatureVectorProvider<DoubleFV> {
68 protected YehSaliency saliencyGenerator;
69 protected float alpha = 0.67f;
70
71 protected double roiProportion;
72
73
74
75
76 public ROIProportion() {
77 saliencyGenerator = new YehSaliency();
78 }
79
80
81
82
83
84
85
86
87 public ROIProportion(float alpha) {
88 this();
89 this.alpha = alpha;
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 public ROIProportion(float saliencySigma, float segmenterSigma, float k, int minSize, float alpha) {
108 saliencyGenerator = new YehSaliency(saliencySigma, segmenterSigma, k, minSize);
109 this.alpha = alpha;
110 }
111
112 @Override
113 public DoubleFV getFeatureVector() {
114 return new DoubleFV(new double[] { roiProportion });
115 }
116
117
118
119
120
121
122
123
124 @Override
125 public void analyseImage(MBFImage image) {
126 image.analyseWith(saliencyGenerator);
127 final TObjectFloatHashMap<ConnectedComponent> componentMap = saliencyGenerator.getSaliencyComponents();
128
129 final float max = ArrayUtils.maxValue(componentMap.values());
130
131 final FImage map = new FImage(image.getWidth(), image.getHeight());
132 final float thresh = max * alpha;
133 final BoundingBoxRenderer<Float> renderer = new BoundingBoxRenderer<Float>(map, 1F, true);
134
135 componentMap.forEachEntry(new TObjectFloatProcedure<ConnectedComponent>() {
136 @Override
137 public boolean execute(ConnectedComponent cc, float sal) {
138 if (sal >= thresh) {
139
140
141 renderer.process(cc);
142 }
143
144 return true;
145 }
146 });
147
148 roiProportion = 0;
149 for (int y = 0; y < map.height; y++)
150 for (int x = 0; x < map.width; x++)
151 roiProportion += map.pixels[y][x];
152
153 roiProportion /= (map.width * map.height);
154
155 }
156 }