Skip to content

Commit dd9a67b

Browse files
committed
add VectorImageView interface with some implementations
1 parent 9b44a1d commit dd9a67b

File tree

7 files changed

+298
-0
lines changed

7 files changed

+298
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
classdef VectorImageMaxChannel < imagem.util.vectorImage.VectorImageView
2+
% One-line description here, please.
3+
%
4+
% Class VectorImageMaxChannel
5+
%
6+
% Example
7+
% VectorImageMaxChannel
8+
%
9+
% See also
10+
%
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-01-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
19+
%% Properties
20+
properties
21+
end % end properties
22+
23+
24+
%% Constructor
25+
methods
26+
function obj = VectorImageMaxChannel(varargin)
27+
% Constructor for VectorImageMaxChannel class.
28+
29+
end
30+
31+
end % end constructors
32+
33+
34+
%% Implementation of VectorImageView
35+
methods
36+
function res = convert(obj, img) %#ok<INUSL>
37+
data = max(img.Data, [], 4);
38+
res = Image('Data', data, 'Parent', img);
39+
end
40+
end % end methods
41+
42+
43+
end % end classdef
44+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
classdef VectorImageNorm < imagem.util.vectorImage.VectorImageView
2+
% One-line description here, please.
3+
%
4+
% Class VectorImageNorm
5+
%
6+
% Example
7+
% VectorImageNorm
8+
%
9+
% See also
10+
%
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-01-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
19+
%% Properties
20+
properties
21+
end % end properties
22+
23+
24+
%% Constructor
25+
methods
26+
function obj = VectorImageNorm(varargin)
27+
% Constructor for VectorImageNorm class.
28+
29+
end
30+
31+
end % end constructors
32+
33+
34+
%% Implementation of VectorImageView
35+
methods
36+
function res = convert(obj, img) %#ok<INUSL>
37+
res = norm(img);
38+
end
39+
end % end methods
40+
41+
42+
end % end classdef
43+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
classdef VectorImageSingleChannel < imagem.util.vectorImage.VectorImageView
2+
% One-line description here, please.
3+
%
4+
% Class VectorImageSingleChannel
5+
%
6+
% Example
7+
% VectorImageSingleChannel
8+
%
9+
% See also
10+
%
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-01-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
19+
%% Properties
20+
properties
21+
ChannelIndex = 1;
22+
end % end properties
23+
24+
25+
%% Constructor
26+
methods
27+
function obj = VectorImageSingleChannel(varargin)
28+
% Constructor for VectorImageSingleChannel class.
29+
if ~isempty(varargin)
30+
obj.ChannelIndex = varargin{1};
31+
end
32+
33+
end
34+
35+
end % end constructors
36+
37+
38+
%% Implementation of VectorImageView
39+
methods
40+
function res = convert(obj, img)
41+
data = img.Data(:,:,:, obj.ChannelIndex,:);
42+
res = Image('Data', data, 'Parent', img);
43+
end
44+
end % end methods
45+
46+
47+
end % end classdef
48+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
classdef VectorImageView < handle
2+
% An interface for representing a multi-channel image as scalar or RGB.
3+
%
4+
% Class VectorImageView
5+
%
6+
% Example
7+
% VectorImageView
8+
%
9+
% See also
10+
%
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-01-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
19+
%% Properties
20+
properties
21+
end % end properties
22+
23+
24+
%% Constructor
25+
methods
26+
function obj = VectorImageView(varargin)
27+
% Constructor for VectorImageView class.
28+
29+
end
30+
31+
end % end constructors
32+
33+
34+
%% Methods
35+
methods (Abstract)
36+
res = convert(obj, img);
37+
end % end methods
38+
39+
end % end classdef
40+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function tests = test_VectorImageMaxChannel
2+
% Test suite for the file VectorImageMaxChannel.
3+
%
4+
% Test suite for the file VectorImageMaxChannel
5+
%
6+
% Example
7+
% test_VectorImageMaxChannel
8+
%
9+
% See also
10+
% VectorImageMaxChannel
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-01-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
21+
function test_constructor(testCase) %#ok<*DEFNU>
22+
% Test call of function without argument.
23+
24+
view = imagem.util.vectorImage.VectorImageMaxChannel();
25+
26+
assertTrue(testCase, isa(view, 'imagem.util.vectorImage.VectorImageMaxChannel'));
27+
28+
29+
function test_convert(testCase) %#ok<*DEFNU>
30+
% Test call of function without argument.
31+
32+
data = 3 * ones([30 20 4]);
33+
img = Image('Data', data, 'vector', true);
34+
view = imagem.util.vectorImage.VectorImageMaxChannel();
35+
36+
res = convert(view, img);
37+
38+
assertTrue(testCase, isa(res, 'Image'));
39+
assertEqual(testCase, size(res), size(img));
40+
assertEqual(testCase, res.Data(1,1), 3.0, 'AbsTol', .01);
41+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function tests = test_VectorImageNorm
2+
% Test suite for the file VectorImageNorm.
3+
%
4+
% Test suite for the file VectorImageNorm
5+
%
6+
% Example
7+
% test_VectorImageNorm
8+
%
9+
% See also
10+
% VectorImageNorm
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-01-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
21+
function test_constructor(testCase) %#ok<*DEFNU>
22+
% Test call of function without argument.
23+
24+
view = imagem.util.vectorImage.VectorImageNorm();
25+
26+
assertTrue(testCase, isa(view, 'imagem.util.vectorImage.VectorImageNorm'));
27+
28+
29+
function test_convert(testCase) %#ok<*DEFNU>
30+
% Test call of function without argument.
31+
32+
data = 3 * ones([30 20 4]);
33+
img = Image('Data', data, 'vector', true);
34+
view = imagem.util.vectorImage.VectorImageNorm();
35+
36+
res = convert(view, img);
37+
38+
assertTrue(testCase, isa(res, 'Image'));
39+
assertEqual(testCase, size(res), size(img));
40+
assertEqual(testCase, res.Data(1,1), 6.0, 'AbsTol', .01);
41+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function tests = test_VectorImageSingleChannel
2+
% Test suite for the file VectorImageSingleChannel.
3+
%
4+
% Test suite for the file VectorImageSingleChannel
5+
%
6+
% Example
7+
% test_VectorImageSingleChannel
8+
%
9+
% See also
10+
% VectorImageSingleChannel
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2021-01-04, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
21+
function test_constructor(testCase) %#ok<*DEFNU>
22+
% Test call of function without argument.
23+
24+
view = imagem.util.vectorImage.VectorImageSingleChannel();
25+
26+
assertTrue(testCase, isa(view, 'imagem.util.vectorImage.VectorImageSingleChannel'));
27+
28+
29+
function test_convert(testCase) %#ok<*DEFNU>
30+
% Test call of function without argument.
31+
32+
data = 3 * ones([30 20 4]);
33+
img = Image('Data', data, 'vector', true);
34+
view = imagem.util.vectorImage.VectorImageSingleChannel();
35+
36+
res = convert(view, img);
37+
38+
assertTrue(testCase, isa(res, 'Image'));
39+
assertEqual(testCase, size(res), size(img));
40+
assertEqual(testCase, res.Data(1,1), 3.0, 'AbsTol', .01);
41+

0 commit comments

Comments
 (0)