001/*******************************************************************************
002 * This software is provided as a supplement to the authors' textbooks on digital
003 *  image processing published by Springer-Verlag in various languages and editions.
004 * Permission to use and distribute this software is granted under the BSD 2-Clause 
005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 
006 * Copyright (c) 2006-2016 Wilhelm Burger, Mark J. Burge. All rights reserved. 
007 * Visit http://imagingbook.com for additional details.
008 *******************************************************************************/
009
010package imagingbook.pub.sift;
011
012import java.util.Locale;
013
014public class KeyPoint implements Cloneable, Comparable<KeyPoint> {
015        public final int p;     // octave index
016        public final int q;     // level index
017        
018        public final int u;     // lattice x-position 
019        public final int v;     // lattice y-position 
020        public float x;         // interpolated lattice x-position 
021        public float y;         // interpolated lattice y-position 
022        
023        public float x_real;    // real x-position (in image coordinates)               
024        public float y_real;    // real y-position (in image coordinates)               
025        public float scale;             // absolute scale
026        
027        public final float magnitude;   // magnitude of DoG response
028        
029        public float[] orientation_histogram;   // for debugging only
030        public double orientation;      // dominant orientation
031        
032//      protected KeyPoint(int p, int q, int u, int v) {
033//              this.p = p;
034//              this.q = q;
035//              this.u = u;
036//              this.v = v;
037//              this.x = u;
038//              this.y = v;
039//      }
040        
041        protected KeyPoint(int p, int q, int u, int v, float x, float y, float x_real, float y_real, float scale, float magnitude) {
042                this.p = p;
043                this.q = q;
044                this.u = u;
045                this.v = v;
046                this.x = x;
047                this.y = y;
048                this.x_real = x_real;
049                this.y_real = y_real;
050                this.scale = scale;
051                this.magnitude = magnitude;
052        }
053        
054        public String toString() {
055                return String.format(Locale.US, "p=%d, q=%d, u=%d, v=%d, scale=%.2f, mag=%.2f", p, q, u, v, scale, magnitude);
056        }
057        
058        public KeyPoint clone() {
059                try {
060                        return (KeyPoint) super.clone();
061                } catch (CloneNotSupportedException e) {
062                        e.printStackTrace();
063                }
064                return null;
065        }
066
067        public int compareTo(KeyPoint c2) {
068                //used for sorting keypoints by magnitude
069                if (this.magnitude > c2.magnitude) return -1;
070                if (this.magnitude < c2.magnitude) return 1;
071                else return 0;
072        }
073        
074        
075
076}