wolffd@0
|
1 function montageKPM2(data)
|
wolffd@0
|
2 % data(y,x,b,f) or data(y,x,f)
|
wolffd@0
|
3 % can be double - uses imagesc to display, not imshow
|
wolffd@0
|
4 % based on imaqmontage
|
wolffd@0
|
5
|
wolffd@0
|
6 if ndims(data)==3
|
wolffd@0
|
7 nr = size(data,1); nc = size(data,2); Npatches = size(data,3); Nbands = 1;
|
wolffd@0
|
8 data = reshape(data, [nr nc Nbands Npatches]);
|
wolffd@0
|
9 else
|
wolffd@0
|
10 nr = size(data,1); nc = size(data,2); Nbands = size(data,3); Npatches = size(data,4);
|
wolffd@0
|
11 end
|
wolffd@0
|
12 nativeVal = data(1, 1);
|
wolffd@0
|
13 dataOrig = data;
|
wolffd@0
|
14
|
wolffd@0
|
15 %put a black border around them for display purposes
|
wolffd@0
|
16 border = 5;
|
wolffd@0
|
17 bgColor = min(data(:));
|
wolffd@0
|
18 %bgColor = max(data(:));
|
wolffd@0
|
19 data = bgColor*ones(nr+2*border, nc+2*border, Nbands, Npatches, class(data));
|
wolffd@0
|
20 data(border+1:end-border, border+1:end-border, :, :) = dataOrig;
|
wolffd@0
|
21
|
wolffd@0
|
22 [width, height, bands, nFrames] = size(data);
|
wolffd@0
|
23
|
wolffd@0
|
24 % Determine the number of axis rows and columns.
|
wolffd@0
|
25 axCols = sqrt(nFrames);
|
wolffd@0
|
26 if (axCols<1)
|
wolffd@0
|
27 % In case we have a slim image.
|
wolffd@0
|
28 axCols = 1;
|
wolffd@0
|
29 end
|
wolffd@0
|
30 axRows = nFrames/axCols;
|
wolffd@0
|
31 if (ceil(axCols)-axCols) < (ceil(axRows)-axRows),
|
wolffd@0
|
32 axCols = ceil(axCols);
|
wolffd@0
|
33 axRows = ceil(nFrames/axCols);
|
wolffd@0
|
34 else
|
wolffd@0
|
35 axRows = ceil(axRows);
|
wolffd@0
|
36 axCols = ceil(nFrames/axRows);
|
wolffd@0
|
37 end
|
wolffd@0
|
38
|
wolffd@0
|
39 % Size the storage to hold all frames.
|
wolffd@0
|
40 storage = repmat(nativeVal, [axRows*width, axCols*height, bands, 1]);
|
wolffd@0
|
41
|
wolffd@0
|
42 % Fill the storage up with data pixels.
|
wolffd@0
|
43 rows = 1:width;
|
wolffd@0
|
44 cols = 1:height;
|
wolffd@0
|
45 for i=0:axRows-1,
|
wolffd@0
|
46 for j=0:axCols-1,
|
wolffd@0
|
47 k = j+i*axCols+1;
|
wolffd@0
|
48 if k<=nFrames,
|
wolffd@0
|
49 storage(rows+i*width, cols+j*height, :) = data(:,:,:,k);
|
wolffd@0
|
50 else
|
wolffd@0
|
51 break;
|
wolffd@0
|
52 end
|
wolffd@0
|
53 end
|
wolffd@0
|
54 end
|
wolffd@0
|
55
|
wolffd@0
|
56
|
wolffd@0
|
57 % Display the tiled frames nicely and
|
wolffd@0
|
58 % pop the window forward.
|
wolffd@0
|
59 im = imagesc(storage);
|
wolffd@0
|
60
|
wolffd@0
|
61 ax = get(im, 'Parent');
|
wolffd@0
|
62 fig = get(ax, 'Parent');
|
wolffd@0
|
63 set(ax, 'XTick', [], 'YTick', [])
|
wolffd@0
|
64 figure(fig)
|
wolffd@0
|
65
|
wolffd@0
|
66 % If working with single band images, update the colormap.
|
wolffd@0
|
67 if 0 % bands==1,
|
wolffd@0
|
68 colormap(gray);
|
wolffd@0
|
69 end
|