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.model.landmark;
031
032import org.openimaj.image.Image;
033import org.openimaj.math.geometry.point.Point2d;
034import org.openimaj.math.geometry.point.PointList;
035import org.openimaj.util.pair.ObjectFloatPair;
036
037/**
038 * A {@link LandmarkModel} models local image content and provides functionality
039 * to move a point in an image to a nearby point with a lower cost than at the
040 * initial point.
041 * <p>
042 * Landmarks are normally associated with points in {@link PointList}s and thus
043 * quite often have an associated "intrinsic scale". This scale can be used to
044 * dynamically change the size of the support region of a landmark so that is
045 * scales with the {@link PointList}s intrinsic scale.
046 * 
047 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
048 * 
049 * @param <I>
050 *            Type of image
051 */
052public interface LandmarkModel<I extends Image<?, I>> {
053        /**
054         * Update the internal model of local image content by adding information
055         * from the provided image.
056         * 
057         * @param image
058         *            the image
059         * @param point
060         *            the point in the image representing the landmark
061         * @param pointList
062         *            the pointList to which the point belongs
063         */
064        public void updateModel(I image, Point2d point, PointList pointList);
065
066        /**
067         * Evaluate the cost function using the given image and point. Lower costs
068         * indicate better fits.
069         * 
070         * @param image
071         *            the image
072         * @param point
073         *            the point in the image
074         * @param pointList
075         *            the pointList to which the point belongs
076         * @return the cost
077         */
078        public float computeCost(I image, Point2d point, PointList pointList);
079
080        /**
081         * Estimate an improved fit based on a local neighbourhood search. Returns
082         * the new best point and the distance moved normalised by the size of the
083         * search area. If the point didn't move, then the distance would be 0; if
084         * the point moved to the extremity of the search region, it would be 1.0.
085         * 
086         * @param image
087         *            the image
088         * @param initial
089         *            the initial point in the image
090         * @param pointList
091         *            the pointList to which the point belongs
092         * @return the updated point
093         */
094        public ObjectFloatPair<Point2d> updatePosition(I image, Point2d initial, PointList pointList);
095}