Skip to content

Commit 52a9b80

Browse files
committed
add tests for morphological operators
1 parent d5d0677 commit 52a9b80

File tree

8 files changed

+323
-0
lines changed

8 files changed

+323
-0
lines changed

tests/image/test_blackTopHat.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function tests = test_blackTopHat
2+
% Test suite for the file blackTopHat.
3+
%
4+
% Test suite for the file blackTopHat
5+
%
6+
% Example
7+
% test_blackTopHat
8+
%
9+
% See also
10+
% blackTopHat
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-02-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
function test_Simple(testCase) %#ok<*DEFNU>
21+
% Test call of function without argument.
22+
23+
data = 150 * ones([16 14], 'uint8');
24+
data(2:4, 2:4) = 50;
25+
data(8:15, 2:4) = 50;
26+
data(8:15, 8:13) = 50;
27+
img = Image('Data', data);
28+
29+
% apply opening making two smallest regions remain
30+
res = blackTopHat(img, ones(5,5));
31+
32+
assertEqual(testCase, size(res), size(img));
33+
assertTrue(testCase, isa(res, 'Image'));
34+
assertEqual(testCase, res.Type, img.Type);
35+
36+
assertEqual(testCase, double(res( 3, 3)), 100);
37+
assertEqual(testCase, double(res(10, 3)), 100);
38+
assertEqual(testCase, double(res( 3, 10)), 0);
39+
assertEqual(testCase, double(res(10, 10)), 0);
40+

tests/image/test_closing.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function tests = test_closing
2+
% Test suite for the file closing.
3+
%
4+
% Test suite for the file closing
5+
%
6+
% Example
7+
% test_closing
8+
%
9+
% See also
10+
% closing
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-02-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
function test_Simple(testCase) %#ok<*DEFNU>
21+
% Test call of function without argument.
22+
23+
data = 150 * ones([16 14], 'uint8');
24+
data(2:4, 2:4) = 50;
25+
data(2:4, 8:13) = 50;
26+
data(8:15, 8:13) = 50;
27+
img = Image('Data', data);
28+
29+
% apply opening making two smallest dark regions disappear
30+
res = closing(img, ones(5,5));
31+
32+
assertEqual(testCase, size(res), size(img));
33+
assertTrue(testCase, isa(res, 'Image'));
34+
assertEqual(testCase, res.Type, img.Type);
35+
36+
assertEqual(testCase, double(res( 3, 3)), 150);
37+
assertEqual(testCase, double(res(10, 3)), 150);
38+
assertEqual(testCase, double(res(10, 10)), 50);
39+
40+

tests/image/test_dilation.m

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function tests = test_dilation
2+
% Test suite for the file dilation.
3+
%
4+
% Test suite for the file dilation
5+
%
6+
% Example
7+
% test_dilation
8+
%
9+
% See also
10+
% dilation
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-02-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
function test_Simple(testCase) %#ok<*DEFNU>
21+
% Test call of function without argument.
22+
23+
data = zeros([16 14], 'uint8');
24+
data(2:4, 2:4) = 150;
25+
data(8:15, 2:4) = 150;
26+
data(8:15, 8:13) = 150;
27+
img = Image('Data', data);
28+
29+
% apply opening making two smallest regions disappear
30+
res = dilation(img, ones(5,5));
31+
32+
assertEqual(testCase, size(res), size(img));
33+
assertTrue(testCase, isa(res, 'Image'));
34+
assertEqual(testCase, res.Type, img.Type);
35+
36+
assertEqual(testCase, double(res( 3, 3)), 150);
37+
assertEqual(testCase, double(res(10, 3)), 150);
38+
assertEqual(testCase, double(res( 3, 10)), 0);
39+
assertEqual(testCase, double(res(10, 10)), 150);

tests/image/test_erosion.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function tests = test_erosion
2+
% Test suite for the file erosion.
3+
%
4+
% Test suite for the file erosion
5+
%
6+
% Example
7+
% test_erosion
8+
%
9+
% See also
10+
% erosion
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-02-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
function test_Simple(testCase) %#ok<*DEFNU>
21+
% Test call of function without argument.
22+
23+
data = zeros([16 14], 'uint8');
24+
data(2:4, 2:4) = 150;
25+
data(8:15, 2:4) = 150;
26+
data(8:15, 8:13) = 150;
27+
img = Image('Data', data);
28+
29+
% apply opening making two smallest regions disappear
30+
res = erosion(img, ones(5,5));
31+
32+
assertEqual(testCase, size(res), size(img));
33+
assertTrue(testCase, isa(res, 'Image'));
34+
assertEqual(testCase, res.Type, img.Type);
35+
36+
assertEqual(testCase, double(res( 3, 3)), 0);
37+
assertEqual(testCase, double(res(10, 3)), 0);
38+
assertEqual(testCase, double(res( 3, 10)), 0);
39+
assertEqual(testCase, double(res(10, 10)), 150);
40+

tests/image/test_morphoGradient.m

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function tests = test_morphoGradient
2+
% Test suite for the file morphoGradient.
3+
%
4+
% Test suite for the file morphoGradient
5+
%
6+
% Example
7+
% test_morphoGradient
8+
%
9+
% See also
10+
% morphoGradient
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-02-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
function test_Simple(testCase) %#ok<*DEFNU>
21+
% Test call of function without argument.
22+
23+
data = zeros([16 14], 'uint8');
24+
data(2:4, 2:4) = 150;
25+
data(8:15, 2:4) = 150;
26+
data(8:15, 8:13) = 150;
27+
img = Image('Data', data);
28+
29+
% apply opening making two smallest regions disappear
30+
res = morphoGradient(img, ones(3,3));
31+
32+
assertEqual(testCase, size(res), size(img));
33+
assertTrue(testCase, isa(res, 'Image'));
34+
assertEqual(testCase, res.Type, img.Type);
35+
36+
assertEqual(testCase, double(res( 3, 3)), 0);
37+
assertEqual(testCase, double(res(10, 3)), 0);
38+
assertEqual(testCase, double(res( 3, 10)), 0);
39+
assertEqual(testCase, double(res(10, 10)), 0);
40+
41+
assertEqual(testCase, double(res( 2, 4)), 150);
42+
assertEqual(testCase, double(res( 4, 2)), 150);
43+
assertEqual(testCase, double(res(10, 4)), 150);
44+

tests/image/test_morphoLaplacian.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function tests = test_morphoLaplacian
2+
% Test suite for the file morphoLaplacian.
3+
%
4+
% Test suite for the file morphoLaplacian
5+
%
6+
% Example
7+
% test_morphoLaplacian
8+
%
9+
% See also
10+
% morphoLaplacian
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-02-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
function test_Simple(testCase) %#ok<*DEFNU>
21+
% Test call of function without argument.
22+
23+
data = zeros([16 14], 'uint8');
24+
data(2:4, 2:4) = 150;
25+
data(8:15, 2:4) = 150;
26+
data(8:15, 8:13) = 150;
27+
img = Image('Data', data);
28+
29+
% apply opening making two smallest regions disappear
30+
res = morphoLaplacian(img, ones(3,3));
31+
32+
assertEqual(testCase, size(res), size(img));
33+
assertTrue(testCase, isa(res, 'Image'));
34+
35+
assertEqual(testCase, double(res( 3, 3)), 0);
36+
assertEqual(testCase, double(res(10, 3)), 0);
37+
assertEqual(testCase, double(res( 3, 10)), 0);
38+
assertEqual(testCase, double(res(10, 10)), 0);
39+
40+
assertNotEqual(testCase, double(res( 2, 4)), 0);
41+
assertNotEqual(testCase, double(res( 4, 2)), 0);
42+
assertNotEqual(testCase, double(res(10, 4)), 0);

tests/image/test_opening.m

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function tests = test_opening
2+
% Test suite for the file opening.
3+
%
4+
% Test suite for the file opening
5+
%
6+
% Example
7+
% test_opening
8+
%
9+
% See also
10+
% opening
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-02-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
function test_Simple(testCase) %#ok<*DEFNU>
21+
% Test call of function without argument.
22+
23+
data = zeros([16 14], 'uint8');
24+
data(2:4, 2:4) = 150;
25+
data(2:4, 8:13) = 150;
26+
data(8:15, 8:13) = 150;
27+
img = Image('Data', data);
28+
29+
% apply opening making two smallest regions disappear
30+
res = opening(img, ones(5,5));
31+
32+
assertEqual(testCase, size(res), size(img));
33+
assertTrue(testCase, isa(res, 'Image'));
34+
assertEqual(testCase, res.Type, img.Type);
35+
36+
assertEqual(testCase, double(res( 3, 3)), 0);
37+
assertEqual(testCase, double(res(10, 3)), 0);
38+
assertEqual(testCase, double(res(10, 10)), 150);

tests/image/test_whiteTopHat.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function tests = test_whiteTopHat
2+
% Test suite for the file whiteTopHat.
3+
%
4+
% Test suite for the file whiteTopHat
5+
%
6+
% Example
7+
% test_whiteTopHat
8+
%
9+
% See also
10+
% whiteTopHat
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-02-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
function test_Simple(testCase) %#ok<*DEFNU>
21+
% Test call of function without argument.
22+
23+
data = zeros([16 14], 'uint8');
24+
data(2:4, 2:4) = 150;
25+
data(8:15, 2:4) = 150;
26+
data(8:15, 8:13) = 150;
27+
img = Image('Data', data);
28+
29+
% apply opening making two smallest regions remain
30+
res = whiteTopHat(img, ones(5,5));
31+
32+
assertEqual(testCase, size(res), size(img));
33+
assertTrue(testCase, isa(res, 'Image'));
34+
assertEqual(testCase, res.Type, img.Type);
35+
36+
assertEqual(testCase, double(res( 3, 3)), 150);
37+
assertEqual(testCase, double(res(10, 3)), 150);
38+
assertEqual(testCase, double(res( 3, 10)), 0);
39+
assertEqual(testCase, double(res(10, 10)), 0);
40+

0 commit comments

Comments
 (0)