001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030package org.openimaj.image.feature.global; 031 032import org.openimaj.citation.annotation.Reference; 033import org.openimaj.citation.annotation.ReferenceType; 034import org.openimaj.feature.DoubleFV; 035import org.openimaj.feature.FeatureVectorProvider; 036import org.openimaj.image.FImage; 037import org.openimaj.image.MBFImage; 038import org.openimaj.image.analyser.ImageAnalyser; 039import org.openimaj.image.colour.Transforms; 040import org.openimaj.image.pixel.statistics.MaskingHistogramModel; 041import org.openimaj.image.saliency.DepthOfFieldEstimator; 042import org.openimaj.image.saliency.LuoTangSubjectRegion; 043import org.openimaj.math.statistics.distribution.MultidimensionalHistogram; 044 045/** 046 * Estimate the simplicity of an image by looking at the 047 * colour distribution of the background using the algorithm 048 * defined by Yiwen Luo and Xiaoou Tang. 049 * 050 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 051 */ 052@Reference( 053 type = ReferenceType.Inproceedings, 054 author = { "Luo, Yiwen", "Tang, Xiaoou" }, 055 title = "Photo and Video Quality Evaluation: Focusing on the Subject", 056 year = "2008", 057 booktitle = "Proceedings of the 10th European Conference on Computer Vision: Part III", 058 pages = { "386", "399" }, 059 url = "http://dx.doi.org/10.1007/978-3-540-88690-7_29", 060 publisher = "Springer-Verlag", 061 series = "ECCV '08", 062 customData = { 063 "isbn", "978-3-540-88689-1", 064 "location", "Marseille, France", 065 "numpages", "14", 066 "doi", "10.1007/978-3-540-88690-7_29", 067 "acmid", "1478204", 068 "address", "Berlin, Heidelberg" 069 } 070) 071public class LuoSimplicity implements ImageAnalyser<MBFImage>, FeatureVectorProvider<DoubleFV> { 072 LuoTangSubjectRegion extractor; 073 int binsPerBand = 16; 074 float gamma = 0.01f; 075 double simplicity; 076 077 /** 078 * Construct with the defaults of 16 histograms per image band 079 * and a gamma value of 0.01. The defaults are used for the 080 * {@link LuoTangSubjectRegion} extractor. 081 */ 082 public LuoSimplicity() { 083 extractor = new LuoTangSubjectRegion(); 084 } 085 086 /** 087 * Construct with the given parameters. 088 * @param binsPerBand the number of histogram bins per colour band 089 * @param gamma the gamma value for determining the threshold 090 * @param alpha the alpha value. 091 * @param maxKernelSize Maximum kernel size for the {@link DepthOfFieldEstimator}. 092 * @param kernelSizeStep Kernel step size for the {@link DepthOfFieldEstimator}. 093 * @param nbins Number of bins for the {@link DepthOfFieldEstimator}. 094 * @param windowSize window size for the {@link DepthOfFieldEstimator}. 095 */ 096 public LuoSimplicity(int binsPerBand, float gamma, float alpha, int maxKernelSize, int kernelSizeStep, int nbins, int windowSize) { 097 extractor = new LuoTangSubjectRegion(alpha, maxKernelSize, kernelSizeStep, nbins, windowSize); 098 this.binsPerBand = binsPerBand; 099 this.gamma = gamma; 100 } 101 102 @Override 103 public void analyseImage(MBFImage image) { 104 Transforms.calculateIntensityNTSC(image).analyseWith(extractor); 105 final FImage mask = extractor.getROIMap().inverse(); 106 107 final MaskingHistogramModel hm = new MaskingHistogramModel(mask, binsPerBand, binsPerBand, binsPerBand); 108 hm.estimateModel(image); 109 110 final MultidimensionalHistogram fv = hm.getFeatureVector(); 111 final double thresh = gamma* fv.max(); 112 int count = 0; 113 for (final double f : fv.values) { 114 if (f >= thresh) 115 count++; 116 } 117 118 simplicity = (double)count / (double)fv.values.length; 119 } 120 121 @Override 122 public DoubleFV getFeatureVector() { 123 return new DoubleFV(new double[] { simplicity }); 124 } 125}