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.affine;
031
032import org.openimaj.citation.annotation.Reference;
033import org.openimaj.citation.annotation.ReferenceType;
034import org.openimaj.feature.local.list.LocalFeatureList;
035import org.openimaj.feature.local.list.MemoryLocalFeatureList;
036import org.openimaj.image.FImage;
037import org.openimaj.image.Image;
038import org.openimaj.image.feature.local.engine.DoGSIFTEngine;
039import org.openimaj.image.feature.local.engine.DoGSIFTEngineOptions;
040import org.openimaj.image.feature.local.engine.Engine;
041import org.openimaj.image.feature.local.keypoints.Keypoint;
042import org.openimaj.image.processor.SinglebandImageProcessor;
043
044/**
045 * Abstract base implementation of Affine-simulated SIFT (ASIFT).
046 * <p>
047 * This is implemented as an extension of the {@link AffineSimulationExtractor}
048 * which uses a {@link DoGSIFTEngine} to extract SIFT features from each affine
049 * simulation.
050 *
051 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
052 * @author Sina Samangooei (ss@ecs.soton.ac.uk)
053 *
054 * @param <I>
055 *            Type of image
056 * @param <P>
057 *            Type of pixel
058 */
059@Reference(
060                type = ReferenceType.Article,
061                author = { "Morel, Jean-Michel", "Yu, Guoshen" },
062                title = "{ASIFT: A New Framework for Fully Affine Invariant Image Comparison}",
063                year = "2009",
064                journal = "SIAM J. Img. Sci.",
065                publisher = "Society for Industrial and Applied Mathematics")
066public abstract class ASIFT<I extends Image<P, I> & SinglebandImageProcessor.Processable<Float, FImage, I>, P>
067extends
068AffineSimulationExtractor<LocalFeatureList<Keypoint>, Keypoint, I, P>
069{
070        Engine<Keypoint, I> keypointEngine;
071
072        /**
073         * A commonly used option, while all others in {@link DoGSIFTEngineOptions}
074         * are default
075         *
076         * @param hires
077         *            whether the image should be double sized as a first step
078         */
079        public ASIFT(boolean hires) {
080                super();
081
082                final DoGSIFTEngineOptions<I> opts = new DoGSIFTEngineOptions<I>();
083                opts.setDoubleInitialImage(hires);
084                keypointEngine = this.constructEngine(opts);
085        }
086
087        /**
088         * @param opts
089         *            the options required by {@link DoGSIFTEngine} instances
090         */
091        public ASIFT(DoGSIFTEngineOptions<I> opts) {
092                super();
093                keypointEngine = this.constructEngine(opts);
094        }
095
096        /**
097         * An engine which can process images of type <I> and output keypoints
098         *
099         * @param opts
100         * @return various engines
101         */
102        public abstract Engine<Keypoint, I> constructEngine(DoGSIFTEngineOptions<I> opts);
103
104        @Override
105        protected LocalFeatureList<Keypoint> newList() {
106                return new MemoryLocalFeatureList<Keypoint>();
107        }
108
109        @Override
110        protected LocalFeatureList<Keypoint> detectFeatures(I image) {
111                final LocalFeatureList<Keypoint> keys = keypointEngine.findFeatures(image);
112
113                return keys;
114        }
115}