Skip to content

Commit 7467d0a

Browse files
committed
channel: fix management of channel names
1 parent f6ff64b commit 7467d0a

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/@Image/channel.m

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@
3939
pattern, index, nc);
4040
end
4141

42-
% compute the name of the new image
43-
if ~isempty(obj.ChannelNames)
44-
channelName = obj.ChannelNames{index};
45-
else
46-
channelName = sprintf('channel%d', index);
47-
end
48-
newName = sprintf('%s-%s', obj.Name, channelName);
49-
5042
% determines the new type (vector if several channels are given)
5143
if length(index) == 1
5244
if isfloat(obj.Data)
@@ -61,8 +53,24 @@
6153
newType = 'vector';
6254
end
6355

64-
channelNames = obj.ChannelNames(index);
56+
% compute the channel names of the new image
57+
if ~isempty(obj.ChannelNames)
58+
channelNames = obj.ChannelNames(index);
59+
else
60+
% if channel names were not initialized, use channel numbers
61+
channelNames = cell(1, length(index));
62+
for i = 1:length(index)
63+
channelNames{i} = sprintf('Channel%d', index(i));
64+
end
65+
end
6566

67+
% compute name of new image
68+
if length(channelNames) == 1
69+
newName = sprintf('%s-%s', obj.Name, channelNames{1});
70+
else
71+
newName = sprintf('%s-channels', obj.Name, channelName);
72+
end
73+
6674
% create a new Image
6775
channel = Image('data', obj.Data(:,:,:,index,:), ...
6876
'parent', obj, 'type', newType, 'name', newName, ...

0 commit comments

Comments
 (0)