View Javadoc

1   /**
2    * This source code file is part of a direct port of Stan Birchfield's implementation
3    * of a Kanade-Lucas-Tomasi feature tracker. The original implementation can be found
4    * here: http://www.ces.clemson.edu/~stb/klt/
5    *
6    * As per the original code, the source code is in the public domain, available
7    * for both commercial and non-commercial use.
8    */
9   package org.openimaj.video.tracking.klt;
10  
11  import org.openimaj.image.FImage;
12  import org.openimaj.image.processing.convolution.FGaussianConvolve;
13  
14  /**
15   * A common set of objects, namely the gaussian pyramid for an image and the gradients of each
16   * level of the pyramid
17   * @author Sina Samangooei (ss@ecs.soton.ac.uk)
18   *
19   */
20  public class PyramidSet{
21  	/**
22  	 * @param image
23  	 * @param tc
24  	 */
25  	public PyramidSet(FImage image, TrackingContext tc) {
26  		int nrows = image.height, ncols = image.width;
27  		FImage floatimg2 = image.process(new FGaussianConvolve(tc.computeSmoothSigma()));
28  		this.imgPyr = new Pyramid(ncols, nrows, (int) tc.subsampling, tc.nPyramidLevels);
29  		this.imgPyr.computePyramid(floatimg2, tc.pyramid_sigma_fact);
30  		this.gradx = new Pyramid(ncols, nrows, (int) tc.subsampling, tc.nPyramidLevels);
31  		this.grady = new Pyramid(ncols, nrows, (int) tc.subsampling, tc.nPyramidLevels);
32  		for (int i = 0 ; i < tc.nPyramidLevels ; i++)
33  			tc.computeGradients(imgPyr.img[i], tc.grad_sigma, gradx.img[i], grady.img[i]);
34  	}
35  	/**
36  	 * @param imgPyr
37  	 * @param gradx
38  	 * @param grady
39  	 */
40  	public PyramidSet(Pyramid imgPyr, Pyramid gradx,Pyramid grady) {
41  		this.imgPyr = imgPyr;
42  		this.gradx = gradx;
43  		this.grady = grady;
44  	}
45  	PyramidSet() {
46  		// TODO Auto-generated constructor stub
47  	}
48  	/**
49  	 * the image pyramid
50  	 */
51  	public Pyramid imgPyr;
52  	/**
53  	 * the x gradient pyramid
54  	 */
55  	public Pyramid gradx;
56  	/**
57  	 * the y gradient pyramid
58  	 */
59  	public Pyramid grady;
60  	
61  	/**
62  	 * @return true if the pyramid is null
63  	 */
64  	public boolean isNull() {
65  		return imgPyr == null || grady == null || gradx == null;
66  	}
67  }