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.saliency;
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.MBFImage;
36 import org.openimaj.image.colour.ColourSpace;
37 import org.openimaj.image.processing.convolution.FGaussianConvolve;
38
39
40
41
42
43
44
45
46
47
48 @Reference(
49 type = ReferenceType.Inproceedings,
50 author = { "Achanta, Radhakrishna", "Hemami, Sheila", "Estrada, Francisco", "S{\"u}sstrunk, Sabine" },
51 title = "Frequency-tuned {S}alient {R}egion {D}etection",
52 year = "2009",
53 booktitle = "{IEEE} {I}nternational {C}onference on {C}omputer {V}ision and {P}attern {R}ecognition ({CVPR})",
54 url = "http://infoscience.epfl.ch/record/135217/files/1708.pdf",
55 customData = { "Affiliation", "EPFL", "Details", "http://infoscience.epfl.ch/record/135217", "Keywords", "IVRG; NCCR-MICS; NCCR-MICS/CL4; K-Space; PHAROS; Saliency; Segmentation; Frequency-domain analysis", "Location", "Miami Beach, Florida" }
56 )
57 public class AchantaSaliency implements SaliencyMapGenerator<MBFImage> {
58 protected float sigma;
59 protected FImage map;
60
61
62
63
64
65 public AchantaSaliency(float sigma) {
66 this.sigma = sigma;
67 }
68
69
70
71
72 public AchantaSaliency() {
73 this.sigma = 1;
74 }
75
76
77
78
79 @Override
80 public void analyseImage(MBFImage image) {
81 int width = image.getWidth();
82 int height = image.getHeight();
83
84 MBFImage lab = ColourSpace.convert(image, ColourSpace.CIE_Lab);
85
86 float[][] Lb = lab.getBand(0).pixels;
87 float[][] ab = lab.getBand(1).pixels;
88 float[][] bb = lab.getBand(2).pixels;
89 float mL = 0, ma = 0, mb = 0;
90
91 for (int y=0; y<height; y++) {
92 for (int x=0; x<width; x++) {
93 mL += Lb[y][x];
94 ma += ab[y][x];
95 mb += bb[y][x];
96 }
97 }
98
99 mL /= (height*width);
100 ma /= (height*width);
101 mb /= (height*width);
102
103
104 MBFImage blur = lab.process(new FGaussianConvolve(sigma));
105 Lb = blur.getBand(0).pixels;
106 ab = blur.getBand(1).pixels;
107 bb = blur.getBand(2).pixels;
108
109
110 map = new FImage(width, height);
111 for (int y=0; y<height; y++) {
112 for (int x=0; x<width; x++) {
113 float dL = (Lb[y][x]-mL);
114 float da = (ab[y][x]-ma);
115 float db = (bb[y][x]-mb);
116
117 map.pixels[y][x] = dL*dL + da*da + db*db;
118 }
119 }
120 map.normalise();
121 }
122
123 @Override
124 public FImage getSaliencyMap() {
125 return map;
126 }
127 }