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.local.detector.dog.collector; 031 032 033import org.openimaj.feature.OrientedFeatureVector; 034import org.openimaj.image.FImage; 035import org.openimaj.image.analysis.pyramid.gaussian.GaussianOctave; 036import org.openimaj.image.feature.local.detector.dog.extractor.GradientFeatureExtractor; 037import org.openimaj.image.feature.local.detector.dog.pyramid.DoGOctaveExtremaFinder; 038import org.openimaj.image.feature.local.detector.pyramid.OctaveInterestPointFinder; 039import org.openimaj.image.feature.local.extraction.ScaleSpaceImageExtractorProperties; 040import org.openimaj.image.feature.local.keypoints.MinMaxKeypoint; 041 042/** 043 * Concrete implementation of an {@link AbstractOctaveLocalFeatureCollector} 044 * that collects {@link MinMaxKeypoint}s with the feature vector provided by the 045 * given feature extractor. {@link MinMaxKeypoint}s contain the x, y and scale 046 * coordinates of the interest point along with its dominant orientation and 047 * a boolean which determines whether the interest point was detected at a local 048 * minima or maxima. 049 * 050 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 051 */ 052public class OctaveMinMaxKeypointCollector extends AbstractOctaveLocalFeatureCollector< 053 GaussianOctave<FImage>, GradientFeatureExtractor, MinMaxKeypoint, FImage> 054{ 055 protected ScaleSpaceImageExtractorProperties<FImage> extractionProperties = new ScaleSpaceImageExtractorProperties<FImage>(); 056 057 /** 058 * Construct with the given feature extractor. 059 * @param featureExtractor the feature extractor. 060 */ 061 public OctaveMinMaxKeypointCollector(GradientFeatureExtractor featureExtractor) { 062 super(featureExtractor); 063 } 064 065 @Override 066 public void foundInterestPoint(OctaveInterestPointFinder<GaussianOctave<FImage>, FImage> finder, float x, float y, float octaveScale) { 067 int currentScaleIndex = finder.getCurrentScaleIndex(); 068 extractionProperties.image = finder.getOctave().images[currentScaleIndex]; 069 extractionProperties.scale = octaveScale; 070 extractionProperties.x = x; 071 extractionProperties.y = y; 072 073 float octSize = finder.getOctave().octaveSize; 074 075 boolean isMaxima = ((DoGOctaveExtremaFinder)finder).getDoGOctave().images[currentScaleIndex].pixels[Math.round(y)][Math.round(x)] > 0.0; 076 077 addFeature(octSize * x, octSize * y, octSize * octaveScale, isMaxima); 078 } 079 080 protected void addFeature(float imx, float imy, float imscale, boolean isMaxima) { 081 OrientedFeatureVector[] fvs = featureExtractor.extractFeature(extractionProperties); 082 083 for (OrientedFeatureVector fv : fvs) { 084 features.add(new MinMaxKeypoint(imx, imy, fv.orientation, imscale, fv.values, isMaxima)); 085 } 086 } 087}