Skip to content

Commit 4d9c2d4

Browse files
committed
Adds tests for Filters, Integral Image, Responses
1 parent b1071ef commit 4d9c2d4

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

test/censure.jl

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using FactCheck, Base.Test, Images, Colors, FixedPointNumbers, ImageFeatures
2+
3+
facts("CENSURE") do
4+
5+
context("Filters") do
6+
7+
bf = BoxFilter(1)
8+
@fact bf.scale --> 1
9+
@fact bf.in_length --> 3
10+
@fact bf.out_length --> 5
11+
@fact bf.in_area --> 9.0
12+
@fact bf.out_area --> 25.0
13+
@fact isapprox(bf.in_weight, 1 / 9) --> true
14+
@fact isapprox(bf.out_weight, 1 / 16) --> true
15+
bf = BoxFilter(5)
16+
@fact bf.scale --> 5
17+
@fact bf.in_length --> 11
18+
@fact bf.out_length --> 21
19+
@fact bf.in_area --> 121.0
20+
@fact bf.out_area --> 441.0
21+
@fact isapprox(bf.in_weight, 1 / 121) --> true
22+
@fact isapprox(bf.out_weight, 1 / 320) --> true
23+
24+
of = OctagonFilter(5, 3, 2, 0)
25+
@fact of.m_out --> 5
26+
@fact of.m_in --> 3
27+
@fact of.n_out --> 2
28+
@fact of.n_in --> 0
29+
@fact of.in_area --> 9.0
30+
@fact of.out_area --> 73.0
31+
@fact isapprox(of.in_weight, 1 / 9) --> true
32+
@fact isapprox(of.out_weight, 1 / 64) --> true
33+
34+
of = OctagonFilter(13, 5, 7, 4)
35+
@fact of.m_out --> 13
36+
@fact of.m_in --> 5
37+
@fact of.n_out --> 7
38+
@fact of.n_in --> 4
39+
@fact of.in_area --> 137.0
40+
@fact of.out_area --> 631.0
41+
@fact isapprox(of.in_weight, 1 / 137) --> true
42+
@fact isapprox(of.out_weight, 1 / 494) --> true
43+
44+
end
45+
46+
context("Integral Image") do
47+
48+
img = ones(5, 5)
49+
bf = BoxFilter(1)
50+
@fact all(integral_image(img) .== ImageFeatures._get_integral_image(img, bf)) --> true
51+
52+
of = OctagonFilter(5, 3, 2, 0)
53+
i, rs, ls = ImageFeatures._get_integral_image(img, of)
54+
@fact all(i .== integral_image(img)) --> true
55+
r_check = [ 1.0 2.0 3.0 4.0 5.0
56+
3.0 5.0 7.0 9.0 10.0
57+
6.0 9.0 12.0 14.0 15.0
58+
10.0 14.0 17.0 19.0 20.0
59+
15.0 19.0 22.0 24.0 25.0 ]
60+
@fact all(rs .== r_check) --> true
61+
l_check = [ 1.0 2.0 3.0 4.0 5.0
62+
1.0 3.0 5.0 7.0 9.0
63+
1.0 3.0 6.0 9.0 12.0
64+
1.0 3.0 6.0 10.0 14.0
65+
1.0 3.0 6.0 10.0 15.0 ]
66+
@fact all(ls .== l_check) --> true
67+
68+
end
69+
70+
context("Filter Response") do
71+
72+
img = [4.0 2.0 6.0 1.0 1.0 8.0 2.0;
73+
9.0 3.0 8.0 3.0 5.0 8.0 4.0;
74+
4.0 10.0 6.0 2.0 5.0 1.0 5.0;
75+
10.0 5.0 8.0 6.0 6.0 3.0 3.0;
76+
5.0 6.0 4.0 8.0 3.0 3.0 9.0;
77+
3.0 1.0 5.0 6.0 2.0 2.0 2.0;
78+
9.0 3.0 4.0 1.0 10.0 8.0 6.0]
79+
bf = BoxFilter(1)
80+
response = ImageFeatures._filter_response(ImageFeatures._get_integral_image(img, bf), bf)
81+
@fact isapprox(response[4, 4], -0.895833, rtol = 0.001) --> true
82+
@fact isapprox(response[4, 5], 0.888889, rtol = 0.001) --> true
83+
@fact isapprox(response[5, 4], -0.958333, rtol = 0.001) --> true
84+
@fact isapprox(response[5, 5], 0.604167, rtol = 0.001) --> true
85+
@fact all(response[:, 1:3] .== 0) --> true
86+
@fact all(response[1:3, :] .== 0) --> true
87+
@fact all(response[:, 6:6] .== 0) --> true
88+
@fact all(response[6:7, :] .== 0) --> true
89+
90+
img = [ 3.0 5.0 8.0 8.0 5.0 4.0 1.0
91+
3.0 8.0 6.0 10.0 1.0 5.0 4.0
92+
10.0 1.0 6.0 4.0 10.0 4.0 5.0
93+
2.0 10.0 9.0 4.0 5.0 3.0 7.0
94+
1.0 7.0 5.0 9.0 7.0 6.0 3.0
95+
5.0 6.0 9.0 9.0 1.0 4.0 8.0
96+
2.0 4.0 6.0 9.0 8.0 4.0 10.0]
97+
response = ImageFeatures._filter_response(ImageFeatures._get_integral_image(img, bf), bf)
98+
@fact isapprox(response[4, 4], -0.93056, rtol = 0.001) --> true
99+
@fact isapprox(response[4, 5], -0.02777, rtol = 0.001) --> true
100+
@fact isapprox(response[5, 4], -0.69444, rtol = 0.001) --> true
101+
@fact isapprox(response[5, 5], 1.35417, rtol = 0.001) --> true
102+
@fact all(response[:, 1:3] .== 0) --> true
103+
@fact all(response[1:3, :] .== 0) --> true
104+
@fact all(response[:, 6:6] .== 0) --> true
105+
@fact all(response[6:7, :] .== 0) --> true
106+
107+
end
108+
109+
end

0 commit comments

Comments
 (0)