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.citation.annotation.References; 035import org.openimaj.feature.DoubleFV; 036import org.openimaj.feature.FeatureVectorProvider; 037import org.openimaj.image.FImage; 038import org.openimaj.image.analyser.ImageAnalyser; 039import org.openimaj.image.processing.algorithm.FourierTransform; 040 041/** 042 * Implementation of the blur estimation feature described by Ke, Tang and Jing, 043 * and Yeh et al. 044 * <p> 045 * Basically, this technique estimates the proportion of blurred pixels by 046 * thresholding the power-spectrum (magnitude) of the FFT of the image. Results 047 * are in the range 0-1. A higher number implies a sharper image. 048 * 049 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 050 * 051 */ 052@References( 053 references = { 054 @Reference( 055 type = ReferenceType.Inproceedings, 056 author = { "Ke, Yan", "Tang, Xiaoou", "Jing, Feng" }, 057 title = "The Design of High-Level Features for Photo Quality Assessment", 058 year = "2006", 059 booktitle = "Proceedings of the 2006 IEEE Computer Society Conference on Computer Vision and Pattern Recognition - Volume 1", 060 pages = { "419", "", "426" }, 061 url = "http://dx.doi.org/10.1109/CVPR.2006.303", 062 publisher = "IEEE Computer Society", 063 series = "CVPR '06", 064 customData = { 065 "isbn", "0-7695-2597-0", 066 "numpages", "8", 067 "doi", "10.1109/CVPR.2006.303", 068 "acmid", "1153495", 069 "address", "Washington, DC, USA" 070 } 071 ), 072 @Reference( 073 type = ReferenceType.Inproceedings, 074 author = { "Che-Hua Yeh", "Yuan-Chen Ho", "Brian A. Barsky", "Ming Ouhyoung" }, 075 title = "Personalized Photograph Ranking and Selection System", 076 year = "2010", 077 booktitle = "Proceedings of ACM Multimedia", 078 pages = { "211", "220" }, 079 month = "October", 080 customData = { "location", "Florence, Italy" } 081 ) 082}) 083public class SharpPixelProportion implements ImageAnalyser<FImage>, FeatureVectorProvider<DoubleFV> { 084 double bpp = 0; 085 private float threshold = 2f; 086 087 /** 088 * Construct with a default threshold on Fourier magnitude of 2.0. 089 */ 090 public SharpPixelProportion() { 091 } 092 093 /** 094 * Construct with the given threshold on Fourier magnitude. 095 * 096 * @param threshold 097 * the threshold 098 */ 099 public SharpPixelProportion(float threshold) { 100 this.threshold = threshold; 101 } 102 103 @Override 104 public DoubleFV getFeatureVector() { 105 return new DoubleFV(new double[] { bpp }); 106 } 107 108 /* 109 * (non-Javadoc) 110 * 111 * @see 112 * org.openimaj.image.analyser.ImageAnalyser#analyseImage(org.openimaj.image 113 * .Image) 114 */ 115 @Override 116 public void analyseImage(FImage image) { 117 final FourierTransform ft = new FourierTransform(image, false); 118 final FImage mag = ft.getMagnitude(); 119 120 int count = 0; 121 for (int y = 0; y < mag.height; y++) { 122 for (int x = 0; x < mag.width; x++) { 123 if (Math.abs(mag.pixels[y][x]) > threshold) 124 count++; 125 } 126 } 127 bpp = (double) count / (double) (mag.height * mag.width); 128 } 129 130 /** 131 * @return the proportion of blurred pixels (those with a Fourier magnitude 132 * above the threshold) 133 */ 134 public double getBlurredPixelProportion() { 135 return bpp; 136 } 137}