wolffd@0: function montageKPM2(data) wolffd@0: % data(y,x,b,f) or data(y,x,f) wolffd@0: % can be double - uses imagesc to display, not imshow wolffd@0: % based on imaqmontage wolffd@0: wolffd@0: if ndims(data)==3 wolffd@0: nr = size(data,1); nc = size(data,2); Npatches = size(data,3); Nbands = 1; wolffd@0: data = reshape(data, [nr nc Nbands Npatches]); wolffd@0: else wolffd@0: nr = size(data,1); nc = size(data,2); Nbands = size(data,3); Npatches = size(data,4); wolffd@0: end wolffd@0: nativeVal = data(1, 1); wolffd@0: dataOrig = data; wolffd@0: wolffd@0: %put a black border around them for display purposes wolffd@0: border = 5; wolffd@0: bgColor = min(data(:)); wolffd@0: %bgColor = max(data(:)); wolffd@0: data = bgColor*ones(nr+2*border, nc+2*border, Nbands, Npatches, class(data)); wolffd@0: data(border+1:end-border, border+1:end-border, :, :) = dataOrig; wolffd@0: wolffd@0: [width, height, bands, nFrames] = size(data); wolffd@0: wolffd@0: % Determine the number of axis rows and columns. wolffd@0: axCols = sqrt(nFrames); wolffd@0: if (axCols<1) wolffd@0: % In case we have a slim image. wolffd@0: axCols = 1; wolffd@0: end wolffd@0: axRows = nFrames/axCols; wolffd@0: if (ceil(axCols)-axCols) < (ceil(axRows)-axRows), wolffd@0: axCols = ceil(axCols); wolffd@0: axRows = ceil(nFrames/axCols); wolffd@0: else wolffd@0: axRows = ceil(axRows); wolffd@0: axCols = ceil(nFrames/axRows); wolffd@0: end wolffd@0: wolffd@0: % Size the storage to hold all frames. wolffd@0: storage = repmat(nativeVal, [axRows*width, axCols*height, bands, 1]); wolffd@0: wolffd@0: % Fill the storage up with data pixels. wolffd@0: rows = 1:width; wolffd@0: cols = 1:height; wolffd@0: for i=0:axRows-1, wolffd@0: for j=0:axCols-1, wolffd@0: k = j+i*axCols+1; wolffd@0: if k<=nFrames, wolffd@0: storage(rows+i*width, cols+j*height, :) = data(:,:,:,k); wolffd@0: else wolffd@0: break; wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: % Display the tiled frames nicely and wolffd@0: % pop the window forward. wolffd@0: im = imagesc(storage); wolffd@0: wolffd@0: ax = get(im, 'Parent'); wolffd@0: fig = get(ax, 'Parent'); wolffd@0: set(ax, 'XTick', [], 'YTick', []) wolffd@0: figure(fig) wolffd@0: wolffd@0: % If working with single band images, update the colormap. wolffd@0: if 0 % bands==1, wolffd@0: colormap(gray); wolffd@0: end