|
39 | 39 | pattern, index, nc); |
40 | 40 | end |
41 | 41 |
|
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 | | - |
50 | 42 | % determines the new type (vector if several channels are given) |
51 | 43 | if length(index) == 1 |
52 | 44 | if isfloat(obj.Data) |
|
61 | 53 | newType = 'vector'; |
62 | 54 | end |
63 | 55 |
|
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 |
65 | 66 |
|
| 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 | + |
66 | 74 | % create a new Image |
67 | 75 | channel = Image('data', obj.Data(:,:,:,index,:), ... |
68 | 76 | 'parent', obj, 'type', newType, 'name', newName, ... |
|
0 commit comments