1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.openimaj.image.feature.dense.gradient.dsift;
31
32 import java.io.DataInput;
33 import java.io.DataOutput;
34 import java.io.IOException;
35 import java.io.PrintWriter;
36 import java.util.Scanner;
37 import java.util.StringTokenizer;
38
39 import org.openimaj.feature.FloatFV;
40
41
42
43
44
45
46
47
48
49 public class FloatDSIFTKeypoint
50 extends
51 AbstractDSIFTKeypoint<FloatFV, float[]>
52 {
53 static final long serialVersionUID = 12345545L;
54
55
56
57
58 public FloatDSIFTKeypoint() {
59 this(DEFAULT_LENGTH);
60 }
61
62
63
64
65
66
67
68 public FloatDSIFTKeypoint(int length) {
69 this.descriptor = new float[length];
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83
84 public FloatDSIFTKeypoint(final float x, final float y, final float[] descriptor, final float energy) {
85 this.x = x;
86 this.y = y;
87 this.descriptor = descriptor;
88 this.energy = energy;
89 }
90
91 @Override
92 public FloatFV getFeatureVector() {
93 return new FloatFV(descriptor);
94 }
95
96 @Override
97 public String toString() {
98 return ("FloatDSIFTKeypoint(" + this.x + ", " + this.y + ")");
99 }
100
101 @Override
102 public void writeBinary(DataOutput out) throws IOException {
103 out.writeFloat(x);
104 out.writeFloat(y);
105 out.writeFloat(energy);
106
107 for (final float f : descriptor)
108 out.writeFloat(f);
109 }
110
111 @Override
112 public void writeASCII(PrintWriter out) throws IOException {
113
114 out.write(x + " " + y + " " + energy + "\n");
115
116 for (int i = 0; i < descriptor.length; i++) {
117 if (i > 0 && i % 20 == 0)
118 out.println();
119 out.format(" %f", descriptor[i]);
120 }
121 out.println();
122 }
123
124 @Override
125 public void readBinary(DataInput in) throws IOException {
126 x = in.readFloat();
127 y = in.readFloat();
128 energy = in.readFloat();
129 for (int i = 0; i < descriptor.length; i++)
130 descriptor[i] = in.readFloat();
131 }
132
133 @Override
134 public void readASCII(Scanner in) throws IOException {
135 x = in.nextFloat();
136 y = in.nextFloat();
137 energy = in.nextFloat();
138
139 int i = 0;
140 while (i < descriptor.length) {
141 final String line = in.nextLine();
142 final StringTokenizer st = new StringTokenizer(line);
143
144 while (st.hasMoreTokens()) {
145 descriptor[i] = Float.parseFloat(st.nextToken());
146 i++;
147 }
148 }
149 }
150 }