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.MBFImage;
034import org.openimaj.image.analysis.pyramid.gaussian.GaussianOctave;
035import org.openimaj.image.analysis.pyramid.gaussian.GaussianPyramid;
036import org.openimaj.image.analysis.pyramid.gaussian.GaussianPyramidOptions;
037import org.openimaj.image.feature.local.detector.pyramid.OctaveInterestPointFinder;
038import org.openimaj.image.feature.local.detector.pyramid.OctaveInterestPointListener;
039
040
041/**
042 * A {@link FirstBandDoGOctaveExtremaFinder} is an {@link OctaveInterestPointFinder} that
043 * can be applied to {@link GaussianOctave}s. A {@link FirstBandDoGOctaveExtremaFinder} 
044 * works like a {@link DoGOctaveExtremaFinder}, but with an {@link MBFImage}, however, 
045 * only the first band of the {@link MBFImage} is used to build the DoG pyramid and for
046 * the application of the inner finder. 
047 * 
048 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
049 */
050public class FirstBandDoGOctaveExtremaFinder 
051        implements 
052                OctaveInterestPointFinder<GaussianOctave<MBFImage>, MBFImage>, 
053                OctaveInterestPointListener<GaussianOctave<FImage>, FImage> 
054{
055        GaussianOctave<MBFImage> gaussianOctave; //the Gaussian octave
056        FirstBandDoGOctave 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<MBFImage>, MBFImage> 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 FirstBandDoGOctaveExtremaFinder(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 FirstBandDoGOctaveExtremaFinder(OctaveInterestPointFinder<GaussianOctave<FImage>, FImage> finder, OctaveInterestPointListener<GaussianOctave<MBFImage>, MBFImage> listener) {
076                this(finder);
077                this.listener = listener;
078        }
079
080        @Override
081        public void setOctaveInterestPointListener(OctaveInterestPointListener<GaussianOctave<MBFImage>, MBFImage> listener) {
082                this.listener = listener;
083        }
084        
085        @Override
086        public OctaveInterestPointListener<GaussianOctave<MBFImage>, MBFImage> getOctaveInterestPointListener() {
087                return listener;
088        }
089        
090        @Override
091        public void process(GaussianOctave<MBFImage> octave) {
092                gaussianOctave = octave;
093                
094                GaussianPyramidOptions<FImage> opts = new GaussianPyramidOptions<FImage>(octave.options);
095                GaussianPyramid<FImage> gp = new GaussianPyramid<FImage>(opts);
096                
097                dogOctave = new FirstBandDoGOctave(gp, octave.octaveSize);
098                dogOctave.process(octave);
099                
100                innerFinder.process(dogOctave);
101        }
102
103        @Override
104        public GaussianOctave<MBFImage> getOctave() {
105                return gaussianOctave;
106        }
107        
108        /**
109         * Get the difference-of-Gaussian octave corresponding to
110         * the current Gaussian octave.
111         * @return the difference-of-Gaussian octave
112         */
113        public GaussianOctave<FImage> getDoGOctave() {
114                return dogOctave;
115        }
116
117        @Override
118        public int getCurrentScaleIndex() {
119                return innerFinder.getCurrentScaleIndex();
120        }
121
122        @Override
123        public void foundInterestPoint(OctaveInterestPointFinder<GaussianOctave<FImage>, FImage> finder, float x, float y, float octaveScale) {
124                if (listener != null) listener.foundInterestPoint(this, x, y, octaveScale);
125        }
126}