@@ -54,6 +54,18 @@ test('check window is circular', () => {
54
54
expect ( result ) . toStrictEqual ( [ { column : 1 , row : 0 } ] ) ;
55
55
} ) ;
56
56
57
+ test ( 'triangle center of mass' , ( ) => {
58
+ const image = testUtils . createGreyImage ( [
59
+ [ 0 , 0 , 0 , 1 , 0 ] ,
60
+ [ 0 , 0 , 1 , 1 , 0 ] ,
61
+ [ 0 , 1 , 1 , 1 , 0 ] ,
62
+ [ 0 , 0 , 1 , 1 , 0 ] ,
63
+ [ 0 , 0 , 0 , 1 , 0 ] ,
64
+ ] ) ;
65
+ const result = getPatchIntensityCentroid ( image , { radius : 2 } ) ;
66
+ expect ( result ) . toBeDeepCloseTo ( [ { column : 0.444 , row : 0 } ] ) ;
67
+ } ) ;
68
+
57
69
test ( 'patch, default options' , ( ) => {
58
70
const image = testUtils . load ( 'featureMatching/patch.png' ) ;
59
71
image . invert ( { out : image } ) ;
@@ -74,3 +86,75 @@ test('patch, default options', () => {
74
86
75
87
expect ( result ) . toMatchImageSnapshot ( ) ;
76
88
} ) ;
89
+
90
+ test ( 'better triangle keypoint' , ( ) => {
91
+ const origin = { row : 332 , column : 253 } ;
92
+ const size = 7 ;
93
+ const radius = ( size - 1 ) / 2 ;
94
+
95
+ const cropOrigin = {
96
+ row : origin . row - radius ,
97
+ column : origin . column - radius ,
98
+ } ;
99
+
100
+ const origialImage = testUtils
101
+ . load ( 'featureMatching/polygons/betterScaleneTriangle.png' )
102
+ . convertColor ( ImageColorModel . GREY )
103
+ . invert ( ) ;
104
+
105
+ const image = origialImage . crop ( {
106
+ origin : cropOrigin ,
107
+ width : size ,
108
+ height : size ,
109
+ } ) ;
110
+
111
+ const centroid = getPatchIntensityCentroid ( image , { radius } ) [ 0 ] ;
112
+ expect ( centroid ) . toBeDeepCloseTo ( { column : 1.281 , row : 0.204 } ) ;
113
+
114
+ const center = image . getCoordinates ( ImageCoordinates . CENTER ) ;
115
+
116
+ const point = round ( sum ( center , centroid ) ) ;
117
+
118
+ const result = image . convertColor ( ImageColorModel . RGB ) ;
119
+ result . drawCircle ( center , radius + 1 , { color : [ 255 , 0 , 0 ] , out : result } ) ;
120
+
121
+ result . drawPoints ( [ point ] , { color : [ 0 , 255 , 0 ] , out : result } ) ;
122
+
123
+ expect ( result ) . toMatchImageSnapshot ( ) ;
124
+ } ) ;
125
+
126
+ test ( 'better triangle 90 keypoint' , ( ) => {
127
+ const origin = { row : 730 , column : 291 } ;
128
+ const size = 7 ;
129
+ const radius = ( size - 1 ) / 2 ;
130
+
131
+ const cropOrigin = {
132
+ row : origin . row - radius ,
133
+ column : origin . column - radius ,
134
+ } ;
135
+
136
+ const origialImage = testUtils
137
+ . load ( 'featureMatching/polygons/betterScaleneTriangle90.png' )
138
+ . convertColor ( ImageColorModel . GREY )
139
+ . invert ( ) ;
140
+
141
+ const image = origialImage . crop ( {
142
+ origin : cropOrigin ,
143
+ width : size ,
144
+ height : size ,
145
+ } ) ;
146
+
147
+ const centroid = getPatchIntensityCentroid ( image , { radius } ) [ 0 ] ;
148
+ expect ( centroid ) . toBeDeepCloseTo ( { column : 0.634 , row : - 1.074 } ) ;
149
+
150
+ const center = image . getCoordinates ( ImageCoordinates . CENTER ) ;
151
+
152
+ const point = round ( sum ( center , centroid ) ) ;
153
+
154
+ const result = image . convertColor ( ImageColorModel . RGB ) ;
155
+ result . drawCircle ( center , radius + 1 , { color : [ 255 , 0 , 0 ] , out : result } ) ;
156
+
157
+ result . drawPoints ( [ point ] , { color : [ 0 , 255 , 0 ] , out : result } ) ;
158
+
159
+ expect ( result ) . toMatchImageSnapshot ( ) ;
160
+ } ) ;
0 commit comments