1
- function [data , colNames , coords ] = unfold(obj )
1
+ function [tab , coords ] = unfold(obj )
2
2
% Unfold a vector image.
3
3
%
4
4
% TAB = unfold(VIMG);
5
- % Unfold the vector image VIMG, and returns an array with as many
6
- % rows as the number of pixels in VIMG, and as many columns as the number
7
- % of channels.
5
+ % Unfold the vector image VIMG, and returns a Table with as many rows as
6
+ % the number of pixels in VIMG, and as many columns as the number of
7
+ % channels.
8
+ %
9
+ % [TAB, COORDS] = unfold(VIMG);
10
+ % Also returns an array with the (X,Y) or (X,Y,Z) coordinates of each
11
+ % element of the table.
8
12
%
9
13
% Example
10
14
% img = Image.read('peppers.png');
30
34
if ~isVectorImage(obj )
31
35
return ;
32
36
end
37
+ if frameCount(obj ) > 1
38
+ error(' Can not process multi-frame images' );
39
+ end
33
40
34
41
% size of the table
35
42
nr = elementCount(obj );
36
43
nc = channelCount(obj );
37
44
45
+ % create data table
46
+ tab = Table(reshape(obj .Data , [nr nc ]));
47
+
38
48
% create column names array
39
49
colNames = obj .ChannelNames ;
40
50
if isempty(obj .ChannelNames ) || length(obj .ChannelNames ) ~= nc
44
54
colNames{i } = sprintf(' Ch%02d ' , i );
45
55
end
46
56
end
57
+ tab.ColNames = colNames ;
47
58
48
- % create data table
49
- data = reshape(obj .Data , [nr nc ]);
50
59
51
60
% optionnaly creates table of coordinates
52
- if nargout > 2
61
+ if nargout > 1
53
62
% create sampling grid (iterating over x first)
54
63
lx = 1 : size(obj , 1 );
55
64
ly = 1 : size(obj , 2 );
56
65
if size(obj , 3 ) > 1
57
66
lz = 1 : size(obj , 3 );
58
67
[y , x , z ] = meshgrid(ly , lx , lz );
59
- coords = [x(: ) y(: ) z(: )];
68
+ coords = Table( [x(: ) y(: ) z(: )], { ' x ' , ' y ' , ' z ' }) ;
60
69
else
61
70
[y , x ] = meshgrid(ly , lx );
62
- coords = [x(: ) y(: )];
71
+ coords = Table( [x(: ) y(: )], { ' x ' , ' y ' }) ;
63
72
end
64
73
end
65
74
0 commit comments