@@ -44,45 +44,35 @@ function run(obj, frame) %#ok<INUSL>
4444 return ;
4545 end
4646
47- % size of the table
48- nr = elementNumber (img );
49- nc = channelNumber( img );
47+ % unfold the table
48+ [ data , colNames , coords ] = unfold (img );
49+ tab = Table( data , colNames );
5050
51- % create sampling grid (iterating over x first)
52- lx = 1 : size(img , 1 );
53- ly = 1 : size(img , 2 );
54- [y , x ] = meshgrid(ly , lx );
55- coords = [reshape(x , [numel(x ) 1 ]), reshape(y , [numel(x ) 1 ])];
56-
57- rowNames = cell(nr , 1 );
58- for i = 1 : nr
59- rowNames{i } = sprintf(' x%03d -y%03d ' , coords(i ,: ));
60- end
51+ % create table viewer
52+ [newFrame , newDoc ] = createTableFrame(frame .Gui , tab , frame ); % #ok<ASGLU>
53+ newDoc.ImageSize = size(img , 1 : ndims(img ));
54+
55+ % add to history
56+ string = sprintf(' [tab, names, coords] = unfold(%s );\n ' , doc .Tag );
57+ addToHistory(frame , string );
58+ string = sprintf(' %s = Table(tab, names});\n ' , newDoc .Tag );
59+ addToHistory(frame , string );
6160
62- colNames = cell(1 , nc );
63- for i = 1 : nc
64- colNames{i } = sprintf(' Ch%02d ' , i );
61+ % also create a table for coordinates
62+ if ndims(img ) == 2 % #ok<ISMAT>
63+ coordNames = {' x' , ' y' };
64+ coordStr = ' {'' x'' , '' y'' }' ;
65+ elseif ndims(img ) == 3
66+ coordNames = {' x' , ' y' , ' z' };
67+ coordStr = ' {'' x'' , '' y'' , '' z'' }' ;
6568 end
69+ coordsTable = Table(coords , coordNames );
70+ [coordsFrame , coordsDoc ] = createTableFrame(frame .Gui , coordsTable ); % #ok<ASGLU>
6671
67- data = reshape(img .Data , [nr nc ]);
68- tab = Table(data , colNames , rowNames );
69-
70- coordsTable = Table(coords , {' x' , ' y' }, rowNames );
71- createTableFrame(frame .Gui , coordsTable );
72-
73-
74- % show(tab);
75- [newFrame , newDoc ] = createTableFrame(frame .Gui , tab , frame ); % #ok<ASGLU>
76- newDoc.ImageSize = [size(img , 1 ) size(img , 2 )];
77-
78- % % create a new doc
79- % newDoc = addImageDocument(frame, res);
80- %
81- % % add history
82- % string = sprintf('%s = squeeze(slice(%s, 3, %d));\n', ...
83- % newDoc.Tag, doc.Tag, sliceIndex);
84- string = sprintf(' %% %s <- unfold vector image %s\n ' , newDoc .Tag , doc .Tag );
72+ % add to history
73+ string = sprintf(' %s = Table(coords, %s });\n ' , coordsDoc .Tag , coordStr );
8574 addToHistory(frame , string );
75+
8676 end
8777
8878end % end methods
0 commit comments