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.contour;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35 import org.openimaj.image.FImage;
36 import org.openimaj.image.pixel.Pixel;
37 import org.openimaj.util.function.Operation;
38
39 /**
40 * A contour Following strategy implements a Contour Tracing algorithm that
41 * extracts a boundary from an image
42 * <p>
43 * Many examples can be found in <a href=
44 * "http://www.imageprocessingplace.com/downloads_V3/root_downloads/tutorials/contour_tracing_Abeer_George_Ghuneim/index.html"
45 * >this tutorial</a>.
46 *
47 * @author Sina Samangooei (ss@ecs.soton.ac.uk)
48 */
49 public abstract class ContourFollowingStrategy {
50 /**
51 * Follow the contour, adding each pixel to a list. The first pixel in the
52 * list is guaranteed to the be equal to start
53 *
54 * @param image
55 * the image
56 * @param start
57 * the starting point on the contour
58 * @param from
59 * the pixel that was not a contour
60 * @return a list of contour pixels in the image starting from the start
61 * pixel
62 */
63 public List<Pixel> contour(FImage image, Pixel start, Pixel from) {
64 final List<Pixel> ret = new ArrayList<Pixel>();
65 contour(image, start, from, new Operation<Pixel>() {
66 @Override
67 public void perform(Pixel object) {
68 ret.add(object);
69 }
70 });
71 return ret;
72 }
73
74 /**
75 *
76 * Given some starting pixel in an image on a contour and the direction of a
77 * non starting image, return each pixel on a contour from the start pixel
78 * in the image. The first pixel returned must be the start pixel
79 *
80 * @param image
81 * the image
82 * @param start
83 * the first point on the contour
84 * @param from
85 * the pixel that was not a contour
86 * @param operation
87 * the thing to do for each contour pixel found
88 */
89 public abstract void contour(FImage image, Pixel start, Pixel from, final Operation<Pixel> operation);
90
91 }