001/**
002 * This source code file is part of a direct port of Stan Birchfield's implementation
003 * of a Kanade-Lucas-Tomasi feature tracker. The original implementation can be found
004 * here: http://www.ces.clemson.edu/~stb/klt/
005 *
006 * As per the original code, the source code is in the public domain, available
007 * for both commercial and non-commercial use.
008 */
009package org.openimaj.video.tracking.klt;
010
011import org.openimaj.image.FImage;
012import org.openimaj.image.processing.convolution.FGaussianConvolve;
013
014/**
015 * A common set of objects, namely the gaussian pyramid for an image and the gradients of each
016 * level of the pyramid
017 * @author Sina Samangooei (ss@ecs.soton.ac.uk)
018 *
019 */
020public class PyramidSet{
021        /**
022         * @param image
023         * @param tc
024         */
025        public PyramidSet(FImage image, TrackingContext tc) {
026                int nrows = image.height, ncols = image.width;
027                FImage floatimg2 = image.process(new FGaussianConvolve(tc.computeSmoothSigma()));
028                this.imgPyr = new Pyramid(ncols, nrows, (int) tc.subsampling, tc.nPyramidLevels);
029                this.imgPyr.computePyramid(floatimg2, tc.pyramid_sigma_fact);
030                this.gradx = new Pyramid(ncols, nrows, (int) tc.subsampling, tc.nPyramidLevels);
031                this.grady = new Pyramid(ncols, nrows, (int) tc.subsampling, tc.nPyramidLevels);
032                for (int i = 0 ; i < tc.nPyramidLevels ; i++)
033                        tc.computeGradients(imgPyr.img[i], tc.grad_sigma, gradx.img[i], grady.img[i]);
034        }
035        /**
036         * @param imgPyr
037         * @param gradx
038         * @param grady
039         */
040        public PyramidSet(Pyramid imgPyr, Pyramid gradx,Pyramid grady) {
041                this.imgPyr = imgPyr;
042                this.gradx = gradx;
043                this.grady = grady;
044        }
045        PyramidSet() {
046                // TODO Auto-generated constructor stub
047        }
048        /**
049         * the image pyramid
050         */
051        public Pyramid imgPyr;
052        /**
053         * the x gradient pyramid
054         */
055        public Pyramid gradx;
056        /**
057         * the y gradient pyramid
058         */
059        public Pyramid grady;
060        
061        /**
062         * @return true if the pyramid is null
063         */
064        public boolean isNull() {
065                return imgPyr == null || grady == null || gradx == null;
066        }
067}