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.apache.commons.math.stat.descriptive.SummaryStatistics;
33 import org.openimaj.citation.annotation.Reference;
34 import org.openimaj.citation.annotation.ReferenceType;
35 import org.openimaj.feature.DoubleFV;
36 import org.openimaj.feature.FeatureVectorProvider;
37 import org.openimaj.image.FImage;
38 import org.openimaj.image.analyser.ImageAnalyser;
39 import org.openimaj.image.mask.AbstractMaskedObject;
40 import org.openimaj.image.processing.convolution.AverageBoxFilter;
41 import org.openimaj.image.processing.convolution.Laplacian3x3;
42
43
44
45
46
47
48
49
50
51 @Reference(
52 type = ReferenceType.Inproceedings,
53 author = { "Jose San Pedro", "Stefan Siersdorfer" },
54 title = "Ranking and Classifying Attractiveness of Photos in Folksonomies",
55 year = "2009",
56 booktitle = "18th International World Wide Web Conference",
57 pages = { "771", "", "771" },
58 url = "http://www2009.eprints.org/78/",
59 month = "April")
60 public class SharpnessVariation extends AbstractMaskedObject<FImage>
61 implements
62 ImageAnalyser<FImage>,
63 FeatureVectorProvider<DoubleFV>
64 {
65 private final Laplacian3x3 laplacian = new Laplacian3x3();
66 private final AverageBoxFilter average = new AverageBoxFilter(3, 3);
67
68 protected double sharpnessVariation;
69
70
71
72
73 public SharpnessVariation() {
74 super();
75 }
76
77
78
79
80
81
82
83 public SharpnessVariation(FImage mask) {
84 super(mask);
85 }
86
87 @Override
88 public DoubleFV getFeatureVector() {
89 return new DoubleFV(new double[] { sharpnessVariation });
90 }
91
92 @Override
93 public void analyseImage(FImage image) {
94 final FImage limg = image.process(laplacian);
95 final FImage aimg = image.process(average);
96
97 final SummaryStatistics stats = new SummaryStatistics();
98 for (int r = 0; r < limg.height; r++) {
99 for (int c = 0; c < limg.width; c++) {
100 if (mask != null && mask.pixels[r][c] == 0)
101 continue;
102
103 if (aimg.pixels[r][c] != 0) {
104 stats.addValue(Math.abs(limg.pixels[r][c] / aimg.pixels[r][c]));
105 }
106 }
107 }
108
109 sharpnessVariation = stats.getStandardDeviation();
110 }
111
112
113
114
115
116
117
118 public double getSharpnessVariation() {
119 return sharpnessVariation;
120 }
121 }