Skip to content

Commit 208f166

Browse files
committed
refactor tests to use Base.Test instead of FactCheck
1 parent ccdaf2b commit 208f166

File tree

10 files changed

+883
-911
lines changed

10 files changed

+883
-911
lines changed

test/REQUIRE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Colors
2-
FactCheck
32
TestImages
43
@linux ImageMagick
54
@windows ImageMagick

test/brief.jl

Lines changed: 177 additions & 180 deletions
Large diffs are not rendered by default.

test/brisk.jl

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,75 @@
1-
using FactCheck, Images, ImageFeatures, TestImages, Distributions, ColorTypes
1+
using Base.Test, ImageFeatures, Images, TestImages, Distributions, ColorTypes
22

3-
facts("BRISK") do
4-
5-
brisk_params = BRISK(pattern_scale = 2.0)
6-
@fact brisk_params.pattern_scale --> 2.0
7-
pt, st = ImageFeatures._brisk_tables(2.0)
8-
@fact brisk_params.pattern_table --> pt
9-
@fact brisk_params.smoothing_table --> st
3+
brisk_params = BRISK(pattern_scale = 2.0)
4+
@test brisk_params.pattern_scale == 2.0
5+
pt, st = ImageFeatures._brisk_tables(2.0)
6+
@test brisk_params.pattern_table == pt
7+
@test brisk_params.smoothing_table == st
108

11-
context("Testing with Standard Images - Lighthouse (Rotation 45)") do
12-
img = testimage("lighthouse")
13-
img_array_1 = convert(Array{Gray}, img)
14-
img_array_2 = _warp(img_array_1, pi / 4)
9+
@testset "Testing with Standard Images - Lighthouse (Rotation 45)" begin
10+
img = testimage("lighthouse")
11+
img_array_1 = convert(Array{Gray}, img)
12+
img_array_2 = _warp(img_array_1, pi / 4)
1513

16-
features_1 = Features(fastcorners(img_array_1, 12, 0.35))
17-
features_2 = Features(fastcorners(img_array_2, 12, 0.35))
18-
brisk_params = BRISK()
14+
features_1 = Features(fastcorners(img_array_1, 12, 0.35))
15+
features_2 = Features(fastcorners(img_array_2, 12, 0.35))
16+
brisk_params = BRISK()
1917

20-
desc_1, ret_features_1 = create_descriptor(img_array_1, features_1, brisk_params)
21-
desc_2, ret_features_2 = create_descriptor(img_array_2, features_2, brisk_params)
22-
23-
matches = match_keypoints(Keypoints(ret_features_1), Keypoints(ret_features_2), desc_1, desc_2, 0.1)
24-
reverse_keypoints_1 = [_reverserotate(m[1], pi / 4, (256, 384)) for m in matches]
25-
@fact all(isapprox(rk[1], m[2][1], atol = 4) && isapprox(rk[2], m[2][2], atol = 4) for (rk, m) in zip(reverse_keypoints_1, matches)) --> true
26-
end
18+
desc_1, ret_features_1 = create_descriptor(img_array_1, features_1, brisk_params)
19+
desc_2, ret_features_2 = create_descriptor(img_array_2, features_2, brisk_params)
2720

28-
context("Testing with Standard Images - Lighthouse (Rotation 45, Translation (50, 40))") do
29-
img = testimage("lighthouse")
30-
img_array_1 = convert(Array{Gray}, img)
31-
img_temp_2 = _warp(img_array_1, pi / 4)
32-
img_array_2 = _warp(img_temp_2, 50, 40)
21+
matches = match_keypoints(Keypoints(ret_features_1), Keypoints(ret_features_2), desc_1, desc_2, 0.1)
22+
reverse_keypoints_1 = [_reverserotate(m[1], pi / 4, (256, 384)) for m in matches]
23+
@test all(isapprox(rk[1], m[2][1], atol = 4) && isapprox(rk[2], m[2][2], atol = 4) for (rk, m) in zip(reverse_keypoints_1, matches))
24+
end
25+
26+
@testset "Testing with Standard Images - Lighthouse (Rotation 45, Translation (50, 40))" begin
27+
img = testimage("lighthouse")
28+
img_array_1 = convert(Array{Gray}, img)
29+
img_temp_2 = _warp(img_array_1, pi / 4)
30+
img_array_2 = _warp(img_temp_2, 50, 40)
3331

34-
features_1 = Features(fastcorners(img_array_1, 12, 0.35))
35-
features_2 = Features(fastcorners(img_array_2, 12, 0.35))
36-
brisk_params = BRISK()
32+
features_1 = Features(fastcorners(img_array_1, 12, 0.35))
33+
features_2 = Features(fastcorners(img_array_2, 12, 0.35))
34+
brisk_params = BRISK()
3735

38-
desc_1, ret_features_1 = create_descriptor(img_array_1, features_1, brisk_params)
39-
desc_2, ret_features_2 = create_descriptor(img_array_2, features_2, brisk_params)
40-
matches = match_keypoints(Keypoints(ret_features_1), Keypoints(ret_features_2), desc_1, desc_2, 0.1)
41-
reverse_keypoints_1 = [_reverserotate(m[1], pi / 4, (256, 384)) + CartesianIndex(50, 40) for m in matches]
42-
@fact all(isapprox(rk[1], m[2][1], atol = 3) && isapprox(rk[2], m[2][2], atol = 3) for (rk, m) in zip(reverse_keypoints_1, matches)) --> true
36+
desc_1, ret_features_1 = create_descriptor(img_array_1, features_1, brisk_params)
37+
desc_2, ret_features_2 = create_descriptor(img_array_2, features_2, brisk_params)
38+
matches = match_keypoints(Keypoints(ret_features_1), Keypoints(ret_features_2), desc_1, desc_2, 0.1)
39+
reverse_keypoints_1 = [_reverserotate(m[1], pi / 4, (256, 384)) + CartesianIndex(50, 40) for m in matches]
40+
@test all(isapprox(rk[1], m[2][1], atol = 3) && isapprox(rk[2], m[2][2], atol = 3) for (rk, m) in zip(reverse_keypoints_1, matches))
4341
end
4442

45-
context("Testing with Standard Images - Lighthouse (Rotation 75, Translation (50, 40))") do
46-
img = testimage("lighthouse")
47-
img_array_1 = convert(Array{Gray}, img)
48-
img_temp_2 = _warp(img_array_1, 5 * pi / 6)
49-
img_array_2 = _warp(img_temp_2, 50, 40)
43+
@testset "Testing with Standard Images - Lighthouse (Rotation 75, Translation (50, 40))" begin
44+
img = testimage("lighthouse")
45+
img_array_1 = convert(Array{Gray}, img)
46+
img_temp_2 = _warp(img_array_1, 5 * pi / 6)
47+
img_array_2 = _warp(img_temp_2, 50, 40)
5048

51-
features_1 = Features(fastcorners(img_array_1, 12, 0.35))
52-
features_2 = Features(fastcorners(img_array_2, 12, 0.35))
53-
brisk_params = BRISK()
49+
features_1 = Features(fastcorners(img_array_1, 12, 0.35))
50+
features_2 = Features(fastcorners(img_array_2, 12, 0.35))
51+
brisk_params = BRISK()
5452

55-
desc_1, ret_features_1 = create_descriptor(img_array_1, features_1, brisk_params)
56-
desc_2, ret_features_2 = create_descriptor(img_array_2, features_2, brisk_params)
57-
matches = match_keypoints(Keypoints(ret_features_1), Keypoints(ret_features_2), desc_1, desc_2, 0.1)
58-
reverse_keypoints_1 = [_reverserotate(m[1], 5 * pi / 6, (256, 384)) + CartesianIndex(50, 40) for m in matches]
59-
@fact all(isapprox(rk[1], m[2][1], atol = 4) && isapprox(rk[2], m[2][2], atol = 4) for (rk, m) in zip(reverse_keypoints_1, matches)) --> true
60-
end
53+
desc_1, ret_features_1 = create_descriptor(img_array_1, features_1, brisk_params)
54+
desc_2, ret_features_2 = create_descriptor(img_array_2, features_2, brisk_params)
55+
matches = match_keypoints(Keypoints(ret_features_1), Keypoints(ret_features_2), desc_1, desc_2, 0.1)
56+
reverse_keypoints_1 = [_reverserotate(m[1], 5 * pi / 6, (256, 384)) + CartesianIndex(50, 40) for m in matches]
57+
@test all(isapprox(rk[1], m[2][1], atol = 4) && isapprox(rk[2], m[2][2], atol = 4) for (rk, m) in zip(reverse_keypoints_1, matches))
58+
end
6159

62-
context("Testing with Standard Images - Lena (Rotation 45, Translation (10, 20))") do
63-
img = testimage("lena_gray_512")
64-
img_array_1 = convert(Array{Gray}, img)
65-
img_temp_2 = _warp(img_array_1, pi / 4)
66-
img_array_2 = _warp(img_temp_2, 10, 20)
60+
@testset "Testing with Standard Images - Lena (Rotation 45, Translation (10, 20))" begin
61+
img = testimage("lena_gray_512")
62+
img_array_1 = convert(Array{Gray}, img)
63+
img_temp_2 = _warp(img_array_1, pi / 4)
64+
img_array_2 = _warp(img_temp_2, 10, 20)
6765

68-
features_1 = Features(fastcorners(img_array_1, 12, 0.2))
69-
features_2 = Features(fastcorners(img_array_2, 12, 0.2))
70-
brisk_params = BRISK()
66+
features_1 = Features(fastcorners(img_array_1, 12, 0.2))
67+
features_2 = Features(fastcorners(img_array_2, 12, 0.2))
68+
brisk_params = BRISK()
7169

72-
desc_1, ret_features_1 = create_descriptor(img_array_1, features_1, brisk_params)
73-
desc_2, ret_features_2 = create_descriptor(img_array_2, features_2, brisk_params)
74-
matches = match_keypoints(Keypoints(ret_features_1), Keypoints(ret_features_2), desc_1, desc_2, 0.1)
75-
reverse_keypoints_1 = [_reverserotate(m[1], pi / 4, (256, 256)) + CartesianIndex(10, 20) for m in matches]
76-
@fact all(isapprox(rk[1], m[2][1], atol = 4) && isapprox(rk[2], m[2][2], atol = 4) for (rk, m) in zip(reverse_keypoints_1, matches)) --> true
77-
end
78-
end
70+
desc_1, ret_features_1 = create_descriptor(img_array_1, features_1, brisk_params)
71+
desc_2, ret_features_2 = create_descriptor(img_array_2, features_2, brisk_params)
72+
matches = match_keypoints(Keypoints(ret_features_1), Keypoints(ret_features_2), desc_1, desc_2, 0.1)
73+
reverse_keypoints_1 = [_reverserotate(m[1], pi / 4, (256, 256)) + CartesianIndex(10, 20) for m in matches]
74+
@test all(isapprox(rk[1], m[2][1], atol = 4) && isapprox(rk[2], m[2][2], atol = 4) for (rk, m) in zip(reverse_keypoints_1, matches))
75+
end

test/core.jl

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
1-
facts("Core") do
2-
3-
context("Types") do
4-
img = zeros(10, 10)
5-
ids = map(CartesianIndex{2}, [(1, 1), (3, 4), (4, 6), (7, 5), (5, 3)])
6-
7-
img[ids] = 1
8-
9-
keypoints = Keypoints(img)
10-
@fact sort(keypoints) == sort(ids) --> true
11-
@fact Keypoint(1, 2) --> CartesianIndex{2}(1, 2)
12-
13-
features = Features(img)
14-
keypoints = Keypoints(features)
15-
@fact sort(keypoints) == sort(ids) --> true
16-
17-
end
18-
19-
context("Keypoint Matching") do
20-
@fact hamming_distance([false], [false]) == 0 --> true
21-
@fact hamming_distance([false, true], [false, false]) == 0.5 --> true
22-
@fact hamming_distance([false, false, true], [false, false, true]) == 0 --> true
23-
@fact hamming_distance([false, false, true], [false, true, false]) == 2 / 3 --> true
24-
@fact hamming_distance([false], [true]) == 1.0 --> true
25-
26-
k1 = map(CartesianIndex{2}, [(1, 1), (2, 2), (3, 3), (4, 4)])
27-
k2 = map(CartesianIndex{2}, [(5, 5)])
28-
d1 = [[false, false, false],
29-
[false, false, true],
30-
[false, true, false],
31-
[true, true, true]]
32-
d2 = [[false, true, false]]
33-
matches = match_keypoints(k1, k2, d1, d2)
34-
expected_matches = [[CartesianIndex(3, 3), CartesianIndex(5, 5)]]
35-
@fact all(expected_matches .== matches) --> true
36-
37-
k2 = map(CartesianIndex{2}, [(5, 5), (6, 6)])
38-
d2 = [[false, true, false],
39-
[false, false, false]]
40-
matches = match_keypoints(k1, k2, d1, d2)
41-
expected_matches = [[CartesianIndex(3, 3), CartesianIndex(5, 5)],
42-
[CartesianIndex(1, 1), CartesianIndex(6, 6)]]
43-
@fact all(expected_matches .== matches) --> true
44-
end
45-
46-
context("Grade Matches") do
47-
k1 = map(CartesianIndex{2}, [(1,1),(2,1)])
48-
k2 = map(CartesianIndex{2}, [(1,1),(2,1)])
49-
@fact grade_matches(k1, k2, 1) == 1 --> true
50-
@fact grade_matches(k1, k2, 1, (i,j)->(abs(i[1]-j[1]) + abs(i[2]-j[2]))) == 1 --> true
51-
k2 = map(CartesianIndex{2}, [(1,0),(0,1)])
52-
@fact grade_matches(k1, k2, 1) == 0 --> true
53-
@fact grade_matches(k1, k2, 2) == 0.5 --> true
54-
k2 = map(CartesianIndex{2}, [(0,0),(2,1)])
55-
@fact grade_matches(k1, k2, 1.2) == 0.5 --> true
56-
end
57-
end
1+
using Base.Test, ImageFeatures, Images
2+
3+
@testset "Types" begin
4+
img = zeros(10, 10)
5+
ids = map(CartesianIndex{2}, [(1, 1), (3, 4), (4, 6), (7, 5), (5, 3)])
6+
7+
img[ids] = 1
8+
9+
keypoints = Keypoints(img)
10+
@test sort(keypoints) == sort(ids)
11+
@test Keypoint(1, 2) == CartesianIndex{2}(1, 2)
12+
13+
features = Features(img)
14+
keypoints = Keypoints(features)
15+
@test sort(keypoints) == sort(ids)
16+
end
17+
18+
@testset "Keypoint Matching" begin
19+
@test hamming_distance([false], [false]) == 0
20+
@test hamming_distance([false, true], [false, false]) == 0.5
21+
@test hamming_distance([false, false, true], [false, false, true]) == 0
22+
@test hamming_distance([false, false, true], [false, true, false]) == 2 / 3
23+
@test hamming_distance([false], [true]) == 1.0
24+
25+
k1 = map(CartesianIndex{2}, [(1, 1), (2, 2), (3, 3), (4, 4)])
26+
k2 = map(CartesianIndex{2}, [(5, 5)])
27+
d1 = [[false, false, false],
28+
[false, false, true],
29+
[false, true, false],
30+
[true, true, true]]
31+
d2 = [[false, true, false]]
32+
matches = match_keypoints(k1, k2, d1, d2)
33+
expected_matches = [[CartesianIndex(3, 3), CartesianIndex(5, 5)]]
34+
@test all(expected_matches .== matches)
35+
36+
k2 = map(CartesianIndex{2}, [(5, 5), (6, 6)])
37+
d2 = [[false, true, false],
38+
[false, false, false]]
39+
matches = match_keypoints(k1, k2, d1, d2)
40+
expected_matches = [[CartesianIndex(3, 3), CartesianIndex(5, 5)],
41+
[CartesianIndex(1, 1), CartesianIndex(6, 6)]]
42+
@test all(expected_matches .== matches)
43+
end
44+
45+
@testset "Grade Matches" begin
46+
k1 = map(CartesianIndex{2}, [(1,1),(2,1)])
47+
k2 = map(CartesianIndex{2}, [(1,1),(2,1)])
48+
@test grade_matches(k1, k2, 1) == 1
49+
@test grade_matches(k1, k2, 1, (i,j)->(abs(i[1]-j[1]) + abs(i[2]-j[2]))) == 1
50+
k2 = map(CartesianIndex{2}, [(1,0),(0,1)])
51+
@test grade_matches(k1, k2, 1) == 0
52+
@test grade_matches(k1, k2, 2) == 0.5
53+
k2 = map(CartesianIndex{2}, [(0,0),(2,1)])
54+
@test grade_matches(k1, k2, 1.2) == 0.5
55+
end

test/corner.jl

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
1-
using FactCheck, Base.Test, Images, ImageFeatures, ColorTypes
1+
using Base.Test, ImageFeatures, Images, ColorTypes
22

3-
facts("Corners") do
3+
@testset "Orientations" begin
4+
img = zeros(20, 20)
5+
img[6:14, 6:14] = 1
6+
orientations = corner_orientations(img)
7+
orientations_deg = map(rad2deg, orientations)
8+
expected = [45.0, -45.0, 135.0, -135.0]
9+
@test all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected))
10+
orientations = corner_orientations(img, Keypoints(imcorner(img)))
11+
orientations_deg = map(rad2deg, orientations)
12+
@test all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected))
13+
kernel = ones(5, 5)
14+
orientations = corner_orientations(img, kernel)
15+
orientations_deg = map(rad2deg, orientations)
16+
@test all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected))
17+
orientations = corner_orientations(img, Keypoints(imcorner(img)), kernel)
18+
orientations_deg = map(rad2deg, orientations)
19+
@test all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected))
20+
img = zeros(RGB{Float64}, 20, 20)
21+
img[6:14, 6:14] = one(RGB{Float64})
22+
orientations = corner_orientations(img, Keypoints(imcorner(img)), kernel)
23+
orientations_deg = map(rad2deg, orientations)
24+
@test all(isapprox(orientations_deg[i], e) for (i, e) in enumerate(expected))
425

5-
context("Orientations") do
6-
img = zeros(20, 20)
7-
img[6:14, 6:14] = 1
8-
orientations = corner_orientations(img)
9-
orientations_deg = map(rad2deg, orientations)
10-
expected = [45.0, -45.0, 135.0, -135.0]
11-
@fact all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected)) --> true
12-
orientations = corner_orientations(img, Keypoints(imcorner(img)))
13-
orientations_deg = map(rad2deg, orientations)
14-
@fact all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected)) --> true
15-
kernel = ones(5, 5)
16-
orientations = corner_orientations(img, kernel)
17-
orientations_deg = map(rad2deg, orientations)
18-
@fact all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected)) --> true
19-
orientations = corner_orientations(img, Keypoints(imcorner(img)), kernel)
20-
orientations_deg = map(rad2deg, orientations)
21-
@fact all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected)) --> true
22-
img = zeros(RGB{Float64}, 20, 20)
23-
img[6:14, 6:14] = one(RGB{Float64})
24-
orientations = corner_orientations(img, Keypoints(imcorner(img)), kernel)
25-
orientations_deg = map(rad2deg, orientations)
26-
@fact all(isapprox(orientations_deg[i], e) for (i, e) in enumerate(expected)) --> true
27-
28-
img = zeros(20, 20)
29-
diamond = [ 0.0 0.0 0.0 1.0 0.0 0.0 0.0
30-
0.0 0.0 1.0 1.0 1.0 0.0 0.0
31-
0.0 1.0 1.0 1.0 1.0 1.0 0.0
32-
1.0 1.0 1.0 1.0 1.0 1.0 1.0
33-
0.0 1.0 1.0 1.0 1.0 1.0 0.0
34-
0.0 0.0 1.0 1.0 1.0 0.0 0.0
35-
0.0 0.0 0.0 1.0 0.0 0.0 0.0 ]
36-
img[8:14, 8:14] = diamond
37-
orientations = corner_orientations(img)
38-
orientations_deg = map(rad2deg, orientations)
39-
expected = [0.0, 90.0, -90.0, -180.0]
40-
@fact all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected)) --> true
41-
end
42-
43-
end
26+
img = zeros(20, 20)
27+
diamond = [ 0.0 0.0 0.0 1.0 0.0 0.0 0.0
28+
0.0 0.0 1.0 1.0 1.0 0.0 0.0
29+
0.0 1.0 1.0 1.0 1.0 1.0 0.0
30+
1.0 1.0 1.0 1.0 1.0 1.0 1.0
31+
0.0 1.0 1.0 1.0 1.0 1.0 0.0
32+
0.0 0.0 1.0 1.0 1.0 0.0 0.0
33+
0.0 0.0 0.0 1.0 0.0 0.0 0.0 ]
34+
img[8:14, 8:14] = diamond
35+
orientations = corner_orientations(img)
36+
orientations_deg = map(rad2deg, orientations)
37+
expected = [0.0, 90.0, -90.0, -180.0]
38+
@test all(isapprox(orientations_deg[i], e, atol = 0.0001) for (i, e) in enumerate(expected))
39+
end

0 commit comments

Comments
 (0)