Skip to content

Commit 5d9ea51

Browse files
committed
rename findLabels.m to findRegionLabels.m
1 parent 4295f0d commit 5d9ea51

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

src/@Image/findLabels.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
function labels = findLabels(obj)
22
% Find unique labels in a label image.
33
%
4+
% Deprecated: renamed as findRegionLabels
5+
%
46
% output = findLabels(input)
57
%
68
% Example
@@ -16,6 +18,8 @@
1618
% Created: 2018-07-03, using Matlab 9.4.0.813654 (R2018a)
1719
% Copyright 2018 INRA - Cepia Software Platform.
1820

21+
warning('deprecated, use ''findRegionLabels'' instead');
22+
1923
% test special case of binary image based on image type
2024
if isBinaryImage(obj)
2125
labels = 1;

src/@Image/findRegionLabels.m

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
function labels = findRegionLabels(obj)
2+
% Find unique region labels within a label or binary image.
3+
%
4+
% LABELS = findRegionLabels(IMG)
5+
%
6+
% Example
7+
% img = Image.read('coins.png');
8+
% bin = fillHoles(img > 100);
9+
% lbl = componentLabeling(bin);
10+
% labels = findRegionLabels(lbl)'
11+
% labels =
12+
% 1 2 3 4 5 6 7 8 9 10
13+
%
14+
% See also
15+
% regionCentroids, unique
16+
%
17+
18+
% ------
19+
% Author: David Legland
20+
% e-mail: david.legland@inrae.fr
21+
% Created: 2018-07-03, using Matlab 9.4.0.813654 (R2018a)
22+
% Copyright 2018 INRA - Cepia Software Platform.
23+
24+
% test special case of binary image based on image type
25+
if isBinaryImage(obj)
26+
labels = 1;
27+
return;
28+
end
29+
30+
if ~isLabelImage(obj)
31+
error('Requires a label image');
32+
end
33+
34+
if isinteger(obj.Data)
35+
% For integer images, iterates over possible labels
36+
37+
% allocate memory
38+
maxLabel = double(max(obj.Data(:)));
39+
labels = zeros(maxLabel, 1);
40+
41+
% iterate over possible labels
42+
nLabels = 0;
43+
for i = 1:maxLabel
44+
if any(obj.Data(:) == i)
45+
nLabels = nLabels + 1;
46+
labels(nLabels) = i;
47+
end
48+
end
49+
50+
% trim label array
51+
labels = labels(1:nLabels);
52+
53+
else
54+
% use generic processing for floating-point images
55+
labels = unique(obj.Data(:));
56+
labels(labels==0) = [];
57+
end
58+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function tests = test_findRegionLabels
2+
% Test suite for the file findRegionLabels.
3+
%
4+
% Test suite for the file findRegionLabels
5+
%
6+
% Example
7+
% test_findRegionLabels
8+
%
9+
% See also
10+
% findRegionLabels
11+
12+
% ------
13+
% Author: David Legland
14+
% e-mail: david.legland@inrae.fr
15+
% Created: 2021-02-02, 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([10 6], 'uint8');
24+
data(1:2,1:2) = 3;
25+
data(4:8,1:2) = 4;
26+
data(2:5,4:5) = 7;
27+
data(7:10,5:6) = 8;
28+
img = Image('Data', data, 'Type', 'Label');
29+
30+
labels = findRegionLabels(img);
31+
32+
assertEqual(testCase, labels, [3 4 7 8]');
33+
34+

0 commit comments

Comments
 (0)