1 /**
2 * Copyright (c) 2011, The University of Southampton and the individual contributors.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * * Neither the name of the University of Southampton nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package org.openimaj.image.pixel.statistics;
31
32 import org.openimaj.image.Image;
33 import org.openimaj.math.geometry.line.Line2d;
34 import org.openimaj.math.geometry.point.Point2d;
35
36 /**
37 * Interface for classes capable of building "models"
38 * of pixels along a line.
39 *
40 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
41 *
42 * @param <I> Concrete type of {@link Image}
43 */
44 public interface PixelProfileModel<I extends Image<?,I>> {
45 /**
46 * Update the model with a new sample.
47 * @param image the image to extract the sample from
48 * @param line the line across with to sample
49 */
50 public void updateModel(I image, Line2d line);
51
52 /**
53 * Extract numSamples samples from the line in the image and
54 * then compare this model at each overlapping position starting
55 * from the first sample at the beginning of the line.
56 *
57 * numSamples must be bigger than the number of samples used to
58 * construct the model. In addition, callers are responsible for
59 * ensuring the sampling rate between the new samples and the model
60 * is equal.
61 *
62 * The point on the line corresponding to the smallest Mahalanobis
63 * distance is returned.
64 *
65 * @param image the image to sample
66 * @param line the line to sample along
67 * @param numSamples the number of samples to make
68 * @return the "best" position on the line
69 */
70 public Point2d computeNewBest(I image, Line2d line, int numSamples);
71
72 /**
73 * Compute the cost of a vector of samples extracted
74 * along a line in the given image to the internal model.
75 *
76 * @param image the image to sample
77 * @param line the line to sample along
78 * @return the computed cost
79 */
80 public float computeCost(I image, Line2d line);
81
82 /**
83 * Compute the distance between the centre of the given
84 * line and the given point, normalised as a function of
85 * the length of the sampling line.
86 *
87 * @param image the image to sample
88 * @param line the line to sample along
89 * @param numSamples the number of samples to make
90 * @param pt the point to compare
91 * @return the normalised distance (0 means same point; 1 means on end of line)
92 */
93 public float computeMovementDistance(I image, Line2d line, int numSamples, Point2d pt);
94 }