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.pixel.statistics;
031
032import org.openimaj.image.Image;
033import org.openimaj.math.geometry.line.Line2d;
034import org.openimaj.math.geometry.point.Point2d;
035
036/**
037 * Interface for classes capable of building "models"
038 * of pixels along a line.
039 * 
040 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
041 * 
042 * @param <I> Concrete type of {@link Image}
043 */
044public interface PixelProfileModel<I extends Image<?,I>> {
045        /**
046         * Update the model with a new sample.
047         * @param image the image to extract the sample from
048         * @param line the line across with to sample
049         */
050        public void updateModel(I image, Line2d line);
051        
052        /**
053         * Extract numSamples samples from the line in the image and
054         * then compare this model at each overlapping position starting
055         * from the first sample at the beginning of the line.
056         * 
057         * numSamples must be bigger than the number of samples used to
058         * construct the model. In addition, callers are responsible for
059         * ensuring the sampling rate between the new samples and the model
060         * is equal.
061         * 
062         * The point on the line corresponding to the smallest Mahalanobis 
063         * distance is returned.
064         * 
065         * @param image the image to sample
066         * @param line the line to sample along
067         * @param numSamples the number of samples to make
068         * @return the "best" position on the line
069         */
070        public Point2d computeNewBest(I image, Line2d line, int numSamples);
071        
072        /**
073         * Compute the cost of a vector of samples extracted 
074         * along a line in the given image to the internal model. 
075         * 
076         * @param image the image to sample 
077         * @param line the line to sample along
078         * @return the computed cost
079         */
080        public float computeCost(I image, Line2d line);
081        
082        /**
083         * Compute the distance between the centre of the given
084         * line and the given point, normalised as a function of
085         * the length of the sampling line.
086         * 
087         * @param image the image to sample
088         * @param line the line to sample along
089         * @param numSamples the number of samples to make
090         * @param pt the point to compare
091         * @return the normalised distance (0 means same point; 1 means on end of line)
092         */
093        public float computeMovementDistance(I image, Line2d line, int numSamples, Point2d pt);
094}