Skip to content

Commit 4fdd9c6

Browse files
committed
update UnfoldVectorImage.m
1 parent 90542f5 commit 4fdd9c6

File tree

3 files changed

+35
-39
lines changed

3 files changed

+35
-39
lines changed

ImageM/+imagem/+actions/+file/OpenDemoImage.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ function run(obj, frame) %#ok<INUSD>
4242
img = Image.read(obj.ImageName);
4343

4444
% add image to application, and create new display
45-
doc = addImageDocument(frame, img);
45+
frame = createImageFrame(frame, img);
4646

47-
tag = doc.Tag;
47+
tag = frame.Doc.Tag;
4848

4949
% history
5050
string = sprintf('%s = Image.read(''%s'');\n', tag, obj.ImageName);

ImageM/+imagem/+actions/+image/UnfoldVectorImage.m

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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

8878
end % end methods

ImageM/+imagem/+gui/ImagemFrame.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@
4545

4646
%% Methods
4747
methods
48-
48+
function [frame, doc] = createImageFrame(obj, image, varargin)
49+
% Create a new frame for the image based on the current frame.
50+
[frame, doc] = createImageFrame(obj.Gui, image, varargin{:});
51+
if isa(obj, 'imagem.gui.ImageViewer') && ~isempty(obj.Doc)
52+
doc.ChannelDisplayType = obj.Doc.ChannelDisplayType;
53+
end
54+
end
55+
4956
function [doc, viewer] = addImageDocument(obj, image, varargin)
5057
% Create a new frame for the image based on the current frame.
5158
[viewer, doc] = createImageFrame(obj.Gui, image, varargin{:});
52-
% [doc, viewer] = addImageDocument(obj.Gui, image, varargin{:});
53-
if isa(obj, 'imagem.gui.ImageViewer')
59+
if isa(obj, 'imagem.gui.ImageViewer') && ~isempty(obj.Doc)
5460
doc.ChannelDisplayType = obj.Doc.ChannelDisplayType;
5561
end
5662
end

0 commit comments

Comments
 (0)