|
12 | 12 | % tab = unfold(img);
|
13 | 13 | % % Performs basic clustering
|
14 | 14 | % km = kmeans(tab, 6);
|
15 |
| -% % Convert result to imaeg using the 'fold' method |
16 |
| -% img2 = Image.fold(km+1, size(img), 'type', 'label', 'Name', 'km3 labels'); |
| 15 | +% % Convert result to image using the 'fold' method |
| 16 | +% img2 = Image.fold(km+1, size(img), 'Type', 'label', 'Name', 'km6 labels'); |
17 | 17 | % figure; show(label2rgb(img2, 'jet'));
|
18 | 18 | %
|
19 | 19 | % See also
|
|
27 | 27 | % Created: 2020-10-19, using Matlab 9.8.0.1323502 (R2020a)
|
28 | 28 | % Copyright 2020 INRAE.
|
29 | 29 |
|
| 30 | +% process data provided as Table |
| 31 | +tab = []; |
| 32 | +if isa(array, 'Table') |
| 33 | + tab = array; |
| 34 | + array = tab.Data; |
| 35 | +end |
| 36 | + |
| 37 | +% retrieve array size |
30 | 38 | nr = size(array, 1);
|
31 | 39 | nc = size(array, 2);
|
32 | 40 |
|
33 | 41 | if prod(dims) ~= nr
|
34 |
| - error('The number of elements of output image must match the row nomber of array'); |
| 42 | + error('The number of elements of output image must match the row number of array'); |
35 | 43 | end
|
36 | 44 |
|
| 45 | +% allocate memory for image data |
37 | 46 | data = zeros([dims nc], 'like', array);
|
38 | 47 |
|
39 |
| -subs = {':', ':', 1}; |
| 48 | +% copy each column into an image channel |
| 49 | +nd = length(dims); |
| 50 | +subs = [repmat({':'}, 1, nd) {1}]; |
40 | 51 | for i = 1:nc
|
41 | 52 | subs{end} = i;
|
42 | 53 | data(subs{:}) = reshape(array(:,i), dims);
|
43 | 54 | end
|
44 | 55 |
|
45 |
| -img = Image('Data', data, 'vector', nc > 1, varargin{:}); |
| 56 | +% Defulat meta-data for new image |
| 57 | +newName = 'fold'; |
| 58 | +if nc == 1 |
| 59 | + channelNames = {'Intensity'}; |
| 60 | +else |
| 61 | + channelNames = cell(1,nc); |
| 62 | + for i = 1:nc |
| 63 | + channelNames{i} = sprintf('Ch%02d', i); |
| 64 | + end |
| 65 | +end |
| 66 | + |
| 67 | +% choose result image name |
| 68 | +if ~isempty(tab) |
| 69 | + if ~isempty(tab.Name) |
| 70 | + newName = [tab.Name '-fold']; |
| 71 | + end |
| 72 | + channelNames = tab.ColNames; |
| 73 | +end |
| 74 | + |
| 75 | +% create result Image |
| 76 | +img = Image('Data', data, 'Vector', nc > 1, ... |
| 77 | + 'Name', newName, ... |
| 78 | + 'ChannelNames', channelNames, ... |
| 79 | + varargin{:}); |
0 commit comments