|
| 1 | +function tests = test_areaOpening |
| 2 | +% Test suite for the file areaOpening. |
| 3 | +% |
| 4 | +% Test suite for the file areaOpening |
| 5 | +% |
| 6 | +% Example |
| 7 | +% test_areaOpening |
| 8 | +% |
| 9 | +% See also |
| 10 | +% areaOpening |
| 11 | + |
| 12 | +% ------ |
| 13 | +% Author: David Legland |
| 14 | +% e-mail: david.legland@inrae.fr |
| 15 | +% Created: 2020-11-25, using Matlab 9.8.0.1323502 (R2020a) |
| 16 | +% Copyright 2020 INRAE - BIA-BIBS. |
| 17 | + |
| 18 | +tests = functiontests(localfunctions); |
| 19 | + |
| 20 | +function test_Simple_binary(testCase) %#ok<*DEFNU> |
| 21 | +% Test call of function without argument. |
| 22 | + |
| 23 | +% create default label image |
| 24 | +data = zeros(8, 8, 'uint8'); |
| 25 | +data(2, 2) = 2; |
| 26 | +data(2, 4:7) = 4; |
| 27 | +data(4:7, 2) = 5; |
| 28 | +data(4:7, 4:7) = 8; |
| 29 | +img = Image(data>0); |
| 30 | + |
| 31 | +imgOp = areaOpening(img, 3); |
| 32 | + |
| 33 | +% expect to keep three connected components |
| 34 | +lbl = componentLabeling(imgOp, 4); |
| 35 | +assertEqual(testCase, max(lbl), 3); |
| 36 | + |
| 37 | + |
| 38 | +function test_Simple_label(testCase) %#ok<*DEFNU> |
| 39 | +% Test call of function without argument. |
| 40 | + |
| 41 | +% create default label image |
| 42 | +data = zeros(8, 8, 'uint8'); |
| 43 | +data(2, 2) = 2; |
| 44 | +data(2, 4:7) = 4; |
| 45 | +data(4:7, 2) = 5; |
| 46 | +data(4:7, 4:7) = 8; |
| 47 | +img = Image(data, 'Type', 'Label'); |
| 48 | + |
| 49 | +imgOp = areaOpening(img, 3); |
| 50 | + |
| 51 | +% expect result to be a label image |
| 52 | +assertTrue(testCase, isLabelImage(imgOp)); |
| 53 | + |
| 54 | +% expect to keep three connected components |
| 55 | +% (recompute labels) |
| 56 | +labelList = unique(imgOp(imgOp>0)); |
| 57 | +assertEqual(testCase, length(labelList), 3); |
| 58 | + |
0 commit comments