1 /**
2 * Copyright (c) 2011, The University of Southampton and the individual contributors.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * * Neither the name of the University of Southampton nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 * Implementation of the saliency map algorithm described in:
41 *
42 * R. Achanta, S. Hemami, F. Estrada and S. Susstrunk, Frequency-tuned Salient
43 * Region Detection, IEEE International Conference on Computer Vision and
44 * Pattern Recognition (CVPR), 2009.
45 *
46 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
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 * Construct with the given amount of smoothing.
63 * @param sigma standard deviation of Gaussian kernel smoothing
64 */
65 public AchantaSaliency(float sigma) {
66 this.sigma = sigma;
67 }
68
69 /**
70 * Construct with a smoothing of 1 pixel standard deviation.
71 */
72 public AchantaSaliency() {
73 this.sigma = 1;
74 }
75
76 /* (non-Javadoc)
77 * @see org.openimaj.image.analyser.ImageAnalyser#analyseImage(org.openimaj.image.Image)
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 //blur
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 //create map
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 }