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