annotate toolboxes/FullBNT-1.0.7/KPMtools/montageKPM2.m @ 0:cc4b1211e677 tip

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