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.processing.transform;
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
38 import org.openimaj.citation.annotation.Reference;
39 import org.openimaj.citation.annotation.ReferenceType;
40 import org.openimaj.io.ReadWriteable;
41
42
43
44
45
46
47 @Reference(
48 type = ReferenceType.Article,
49 author = { "Morel, Jean-Michel", "Yu, Guoshen" },
50 title = "{ASIFT: A New Framework for Fully Affine Invariant Image Comparison}",
51 year = "2009",
52 journal = "SIAM J. Img. Sci.",
53 publisher = "Society for Industrial and Applied Mathematics")
54 public class AffineParams implements ReadWriteable {
55
56
57
58 public float theta;
59
60
61
62
63 public float tilt;
64
65
66
67
68
69
70
71
72
73 public AffineParams(float theta, float tilt) {
74 this.theta = theta;
75 this.tilt = tilt;
76 }
77
78
79
80
81 public AffineParams() {
82 }
83
84 @Override
85 public boolean equals(Object po) {
86 if (po instanceof AffineParams) {
87 final AffineParams p = (AffineParams) po;
88 return (Math.abs(theta - p.theta) < 0.00001 && Math.abs(tilt - p.tilt) < 0.00001);
89 }
90 return false;
91 }
92
93 @Override
94 public int hashCode() {
95 final int hash = new Float(theta).hashCode() ^ new Float(tilt).hashCode();
96 return hash;
97 }
98
99 @Override
100 public String toString() {
101 return String.format("theta:%f tilt:%f", theta, tilt);
102 }
103
104 @Override
105 public void readBinary(DataInput in) throws IOException {
106 this.theta = in.readFloat();
107 this.tilt = in.readFloat();
108 }
109
110 @Override
111 public void readASCII(Scanner in) throws IOException {
112 this.theta = in.nextFloat();
113 this.tilt = in.nextFloat();
114 }
115
116 @Override
117 public byte[] binaryHeader() {
118 return "".getBytes();
119 }
120
121 @Override
122 public String asciiHeader() {
123 return "";
124 }
125
126 @Override
127 public void writeBinary(DataOutput out) throws IOException {
128 out.writeFloat(this.theta);
129 out.writeFloat(this.tilt);
130 }
131
132 @Override
133 public void writeASCII(PrintWriter out) throws IOException {
134 out.println(this.theta);
135 out.println(this.tilt);
136 }
137 }