1- function [data , colNames , coords ] = unfold(obj )
1+ function [tab , coords ] = unfold(obj )
22% Unfold a vector image.
33%
44% 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.
812%
913% Example
1014% img = Image.read('peppers.png');
3034if ~isVectorImage(obj )
3135 return ;
3236end
37+ if frameCount(obj ) > 1
38+ error(' Can not process multi-frame images' );
39+ end
3340
3441% size of the table
3542nr = elementCount(obj );
3643nc = channelCount(obj );
3744
45+ % create data table
46+ tab = Table(reshape(obj .Data , [nr nc ]));
47+
3848% create column names array
3949colNames = obj .ChannelNames ;
4050if isempty(obj .ChannelNames ) || length(obj .ChannelNames ) ~= nc
4454 colNames{i } = sprintf(' Ch%02d ' , i );
4555 end
4656end
57+ tab.ColNames = colNames ;
4758
48- % create data table
49- data = reshape(obj .Data , [nr nc ]);
5059
5160% optionnaly creates table of coordinates
52- if nargout > 2
61+ if nargout > 1
5362 % create sampling grid (iterating over x first)
5463 lx = 1 : size(obj , 1 );
5564 ly = 1 : size(obj , 2 );
5665 if size(obj , 3 ) > 1
5766 lz = 1 : size(obj , 3 );
5867 [y , x , z ] = meshgrid(ly , lx , lz );
59- coords = [x(: ) y(: ) z(: )];
68+ coords = Table( [x(: ) y(: ) z(: )], { ' x ' , ' y ' , ' z ' }) ;
6069 else
6170 [y , x ] = meshgrid(ly , lx );
62- coords = [x(: ) y(: )];
71+ coords = Table( [x(: ) y(: )], { ' x ' , ' y ' }) ;
6372 end
6473end
6574
0 commit comments