wolffd@0
|
1 function h = montageKPM(arg)
|
wolffd@0
|
2 % montageKPM is like the built-in montage, but assumes input is MxNxK or filenames
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % Converts patches (y,x,i) into patches(y,x,1,i)
|
wolffd@0
|
5 % Also, adds a black border aroudn them
|
wolffd@0
|
6
|
wolffd@0
|
7 if iscell(arg)
|
wolffd@0
|
8 h= montageFilenames(arg);
|
wolffd@0
|
9 else
|
wolffd@0
|
10 nr = size(arg,1); nc = size(arg,2); Npatches = size(arg,3);
|
wolffd@0
|
11 patchesColor = reshape(arg, [nr nc 1 Npatches]);
|
wolffd@0
|
12 patchesColor = patchesColor ./ max(patchesColor(:));
|
wolffd@0
|
13
|
wolffd@0
|
14 if 1
|
wolffd@0
|
15 %put a black border around them for display purposes
|
wolffd@0
|
16 border = 5;
|
wolffd@0
|
17 bgColor = ones(1,1,class(patchesColor));
|
wolffd@0
|
18 patchesColorBig = bgColor*ones(nr+2*border, nc+2*border, 1, Npatches, class(patchesColor));
|
wolffd@0
|
19 %patchesColorBig = zeros(nr+2*border, nc+2*border, 1, Npatches, class(patchesColor));
|
wolffd@0
|
20 patchesColorBig(border+1:end-border, border+1:end-border, :, :) = patchesColor;
|
wolffd@0
|
21 else
|
wolffd@0
|
22 patchesColorBig = patchesColor;
|
wolffd@0
|
23 end
|
wolffd@0
|
24 montage(patchesColorBig)
|
wolffd@0
|
25
|
wolffd@0
|
26 end
|
wolffd@0
|
27
|
wolffd@0
|
28 %%%%%%%%%%%%%
|
wolffd@0
|
29
|
wolffd@0
|
30 function h = montageFilenames(filenames)
|
wolffd@0
|
31
|
wolffd@0
|
32 %[nRows, nCols, nBands, nFrames] = size(a);
|
wolffd@0
|
33
|
wolffd@0
|
34 % Estimate nMontageColumns and nMontageRows given the desired ratio of
|
wolffd@0
|
35 % Columns to Rows to be one (square montage).
|
wolffd@0
|
36 aspectRatio = 1;
|
wolffd@0
|
37 nMontageCols = sqrt(aspectRatio * nRows * nFrames / nCols);
|
wolffd@0
|
38
|
wolffd@0
|
39 % Make sure montage rows and columns are integers. The order in the adjustment
|
wolffd@0
|
40 % matters because the montage image is created horizontally across columns.
|
wolffd@0
|
41 nMontageCols = ceil(nMontageCols);
|
wolffd@0
|
42 nMontageRows = ceil(nFrames / nMontageCols);
|
wolffd@0
|
43
|
wolffd@0
|
44 % Create the montage image.
|
wolffd@0
|
45 b = a(1,1); % to inherit type
|
wolffd@0
|
46 b(1,1) = 0; % from a
|
wolffd@0
|
47 b = repmat(b, [nMontageRows*nRows, nMontageCols*nCols, nBands, 1]);
|
wolffd@0
|
48
|
wolffd@0
|
49 rows = 1 : nRows;
|
wolffd@0
|
50 cols = 1 : nCols;
|
wolffd@0
|
51
|
wolffd@0
|
52 for i = 0:nMontageRows-1
|
wolffd@0
|
53 for j = 0:nMontageCols-1,
|
wolffd@0
|
54 k = j + i * nMontageCols + 1;
|
wolffd@0
|
55 if k <= nFrames
|
wolffd@0
|
56 b(rows + i * nRows, cols + j * nCols, :) = a(:,:,:,k);
|
wolffd@0
|
57 else
|
wolffd@0
|
58 break;
|
wolffd@0
|
59 end
|
wolffd@0
|
60 end
|
wolffd@0
|
61 end
|
wolffd@0
|
62
|
wolffd@0
|
63 if isempty(cm)
|
wolffd@0
|
64 hh = imshow(b);
|
wolffd@0
|
65 else
|
wolffd@0
|
66 hh = imshow(b,cm);
|
wolffd@0
|
67 end
|
wolffd@0
|
68
|
wolffd@0
|
69 if nargout > 0
|
wolffd@0
|
70 h = hh;
|
wolffd@0
|
71 end
|
wolffd@0
|
72
|
wolffd@0
|
73 %--------------------------------------------------------------
|
wolffd@0
|
74 %Parse Inputs Function
|
wolffd@0
|
75
|
wolffd@0
|
76 function [I,map] = parse_inputs(varargin)
|
wolffd@0
|
77
|
wolffd@0
|
78 % initialize variables
|
wolffd@0
|
79 map = [];
|
wolffd@0
|
80
|
wolffd@0
|
81 iptchecknargin(1,2,nargin,mfilename);
|
wolffd@0
|
82 iptcheckinput(varargin{1},{'uint8' 'double' 'uint16' 'logical' 'single' ...
|
wolffd@0
|
83 'int16'},{},mfilename, 'I, BW, or RGB',1);
|
wolffd@0
|
84 I = varargin{1};
|
wolffd@0
|
85
|
wolffd@0
|
86 if nargin==2
|
wolffd@0
|
87 if isa(I,'int16')
|
wolffd@0
|
88 eid = sprintf('Images:%s:invalidIndexedImage',mfilename);
|
wolffd@0
|
89 msg1 = 'An indexed image can be uint8, uint16, double, single, or ';
|
wolffd@0
|
90 msg2 = 'logical.';
|
wolffd@0
|
91 error(eid,'%s %s',msg1, msg2);
|
wolffd@0
|
92 end
|
wolffd@0
|
93 map = varargin{2};
|
wolffd@0
|
94 iptcheckinput(map,{'double'},{},mfilename,'MAP',1);
|
wolffd@0
|
95 if ((size(map,1) == 1) && (prod(map) == numel(I)))
|
wolffd@0
|
96 % MONTAGE(D,[M N P]) OBSOLETE
|
wolffd@0
|
97 eid = sprintf('Images:%s:obsoleteSyntax',mfilename);
|
wolffd@0
|
98 msg1 = 'MONTAGE(D,[M N P]) is an obsolete syntax.';
|
wolffd@0
|
99 msg2 = 'Use multidimensional arrays to represent multiframe images.';
|
wolffd@0
|
100 error(eid,'%s\n%s',msg1,msg2);
|
wolffd@0
|
101 end
|
wolffd@0
|
102 end
|