|
| 1 | +function tests = test_regionElementCounts |
| 2 | +% Test suite for the file regionElementCounts. |
| 3 | +% |
| 4 | +% Test suite for the file regionElementCounts |
| 5 | +% |
| 6 | +% Example |
| 7 | +% test_regionElementCounts |
| 8 | +% |
| 9 | +% See also |
| 10 | +% regionElementCounts |
| 11 | + |
| 12 | +% ------ |
| 13 | +% Author: David Legland |
| 14 | +% e-mail: david.legland@inrae.fr |
| 15 | +% Created: 2020-12-02, using Matlab 9.8.0.1323502 (R2020a) |
| 16 | +% Copyright 2020 INRAE - BIA-BIBS. |
| 17 | + |
| 18 | +tests = functiontests(localfunctions); |
| 19 | + |
| 20 | +function test_2d(testCase) %#ok<*DEFNU> |
| 21 | +% Count the elements in a label image with 4 regions. |
| 22 | + |
| 23 | +data = zeros(10, 10); |
| 24 | +data(2, 2) = 1; |
| 25 | +data(2, 4:8) = 3; |
| 26 | +data(4:8, 2) = 4; |
| 27 | +data(4:8, 4:8) = 9; |
| 28 | +img = Image('Data', data, 'Type', 'label'); |
| 29 | + |
| 30 | +counts = regionElementCounts(img); |
| 31 | + |
| 32 | +assertEqual(testCase, length(counts), 4); |
| 33 | +assertEqual(testCase, counts, [1 5 5 25]'); |
| 34 | + |
| 35 | + |
| 36 | +function test_3d(testCase) %#ok<*DEFNU> |
| 37 | +% Count the elements in a label image with 4 regions. |
| 38 | + |
| 39 | +data = zeros(10, 10, 10); |
| 40 | +data(2, 2, 2) = 1; |
| 41 | +data(4:8, 2, 2) = 3; |
| 42 | +data(2, 4:8, 2) = 4; |
| 43 | +data(2, 2, 4:8) = 5; |
| 44 | +data(4:8, 4:8, 2) = 10; |
| 45 | +data(4:8, 2, 4:8) = 12; |
| 46 | +data(2, 4:8, 4:8) = 15; |
| 47 | +data(4:8, 4:8, 4:8) = 19; |
| 48 | +img = Image('Data', data, 'Type', 'label'); |
| 49 | + |
| 50 | +counts = regionElementCounts(img); |
| 51 | + |
| 52 | +assertEqual(testCase, length(counts), 8); |
| 53 | +assertEqual(testCase, counts, [1 5 5 5 25 25 25 125]'); |
| 54 | + |
0 commit comments