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.pyramid; 031 032import org.openimaj.image.FImage; 033import org.openimaj.image.analysis.pyramid.gaussian.GaussianOctave; 034import org.openimaj.image.feature.local.detector.pyramid.OctaveInterestPointFinder; 035import org.openimaj.image.feature.local.detector.pyramid.OctaveInterestPointListener; 036 037 038/** 039 * A DoGOctaveExtremaFinder is an {@link OctaveInterestPointFinder} that 040 * can be applied to {@link GaussianOctave}s. Internally, a Difference-of- 041 * Gaussian octave ({@DoGOctave}) is constructed from the Gaussian octave 042 * and an internal {@link OctaveInterestPointFinder} is applied. Detections 043 * of interest points from the internal finder are proxied through the 044 * DoGOctaveExtremaFinder, and sent to the listener object of the 045 * DoGOctaveExtremaFinder. 046 * 047 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 048 * 049 */ 050public class DoGOctaveExtremaFinder 051 implements 052 OctaveInterestPointFinder<GaussianOctave<FImage>, FImage>, 053 OctaveInterestPointListener<GaussianOctave<FImage>, FImage> 054{ 055 GaussianOctave<FImage> gaussianOctave; //the Gaussian octave 056 DoGOctave<FImage> dogOctave; //a difference-of-Gaussian octave constructed from the Gaussian one 057 OctaveInterestPointFinder<GaussianOctave<FImage>, FImage> innerFinder; //the finder that is applied to the DoG 058 OctaveInterestPointListener<GaussianOctave<FImage>, FImage> listener; //a listener that is fired as interest points are detected 059 060 /** 061 * Construct with the given finder. 062 * @param finder the finder 063 */ 064 public DoGOctaveExtremaFinder(OctaveInterestPointFinder<GaussianOctave<FImage>, FImage> finder) { 065 this.innerFinder = finder; 066 067 finder.setOctaveInterestPointListener(this); 068 } 069 070 /** 071 * Construct with the given finder and listener. 072 * @param finder the finder 073 * @param listener the listener 074 */ 075 public DoGOctaveExtremaFinder(OctaveInterestPointFinder<GaussianOctave<FImage>, FImage> finder, OctaveInterestPointListener<GaussianOctave<FImage>, FImage> listener) { 076 this(finder); 077 this.listener = listener; 078 } 079 080 @Override 081 public void setOctaveInterestPointListener(OctaveInterestPointListener<GaussianOctave<FImage>, FImage> listener) { 082 this.listener = listener; 083 } 084 085 @Override 086 public OctaveInterestPointListener<GaussianOctave<FImage>, FImage> getOctaveInterestPointListener() { 087 return listener; 088 } 089 090 @Override 091 public void process(GaussianOctave<FImage> octave) { 092 gaussianOctave = octave; 093 094 dogOctave = new DoGOctave<FImage>(octave.parentPyramid, octave.octaveSize); 095 dogOctave.process(octave); 096 097 innerFinder.process(dogOctave); 098 } 099 100 @Override 101 public GaussianOctave<FImage> getOctave() { 102 return gaussianOctave; 103 } 104 105 /** 106 * Get the difference-of-Gaussian octave corresponding to 107 * the current Gaussian octave. 108 * @return the difference-of-Gaussian octave 109 */ 110 public GaussianOctave<FImage> getDoGOctave() { 111 return dogOctave; 112 } 113 114 @Override 115 public int getCurrentScaleIndex() { 116 return innerFinder.getCurrentScaleIndex(); 117 } 118 119 @Override 120 public void foundInterestPoint(OctaveInterestPointFinder<GaussianOctave<FImage>, FImage> finder, float x, float y, float octaveScale) { 121 if (listener != null) listener.foundInterestPoint(this, x, y, octaveScale); 122 } 123}