wolffd@0: function h = montageKPM(arg) wolffd@0: % montageKPM is like the built-in montage, but assumes input is MxNxK or filenames wolffd@0: % wolffd@0: % Converts patches (y,x,i) into patches(y,x,1,i) wolffd@0: % Also, adds a black border aroudn them wolffd@0: wolffd@0: if iscell(arg) wolffd@0: h= montageFilenames(arg); wolffd@0: else wolffd@0: nr = size(arg,1); nc = size(arg,2); Npatches = size(arg,3); wolffd@0: patchesColor = reshape(arg, [nr nc 1 Npatches]); wolffd@0: patchesColor = patchesColor ./ max(patchesColor(:)); wolffd@0: wolffd@0: if 1 wolffd@0: %put a black border around them for display purposes wolffd@0: border = 5; wolffd@0: bgColor = ones(1,1,class(patchesColor)); wolffd@0: patchesColorBig = bgColor*ones(nr+2*border, nc+2*border, 1, Npatches, class(patchesColor)); wolffd@0: %patchesColorBig = zeros(nr+2*border, nc+2*border, 1, Npatches, class(patchesColor)); wolffd@0: patchesColorBig(border+1:end-border, border+1:end-border, :, :) = patchesColor; wolffd@0: else wolffd@0: patchesColorBig = patchesColor; wolffd@0: end wolffd@0: montage(patchesColorBig) wolffd@0: wolffd@0: end wolffd@0: wolffd@0: %%%%%%%%%%%%% wolffd@0: wolffd@0: function h = montageFilenames(filenames) wolffd@0: wolffd@0: %[nRows, nCols, nBands, nFrames] = size(a); wolffd@0: wolffd@0: % Estimate nMontageColumns and nMontageRows given the desired ratio of wolffd@0: % Columns to Rows to be one (square montage). wolffd@0: aspectRatio = 1; wolffd@0: nMontageCols = sqrt(aspectRatio * nRows * nFrames / nCols); wolffd@0: wolffd@0: % Make sure montage rows and columns are integers. The order in the adjustment wolffd@0: % matters because the montage image is created horizontally across columns. wolffd@0: nMontageCols = ceil(nMontageCols); wolffd@0: nMontageRows = ceil(nFrames / nMontageCols); wolffd@0: wolffd@0: % Create the montage image. wolffd@0: b = a(1,1); % to inherit type wolffd@0: b(1,1) = 0; % from a wolffd@0: b = repmat(b, [nMontageRows*nRows, nMontageCols*nCols, nBands, 1]); wolffd@0: wolffd@0: rows = 1 : nRows; wolffd@0: cols = 1 : nCols; wolffd@0: wolffd@0: for i = 0:nMontageRows-1 wolffd@0: for j = 0:nMontageCols-1, wolffd@0: k = j + i * nMontageCols + 1; wolffd@0: if k <= nFrames wolffd@0: b(rows + i * nRows, cols + j * nCols, :) = a(:,:,:,k); wolffd@0: else wolffd@0: break; wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: if isempty(cm) wolffd@0: hh = imshow(b); wolffd@0: else wolffd@0: hh = imshow(b,cm); wolffd@0: end wolffd@0: wolffd@0: if nargout > 0 wolffd@0: h = hh; wolffd@0: end wolffd@0: wolffd@0: %-------------------------------------------------------------- wolffd@0: %Parse Inputs Function wolffd@0: wolffd@0: function [I,map] = parse_inputs(varargin) wolffd@0: wolffd@0: % initialize variables wolffd@0: map = []; wolffd@0: wolffd@0: iptchecknargin(1,2,nargin,mfilename); wolffd@0: iptcheckinput(varargin{1},{'uint8' 'double' 'uint16' 'logical' 'single' ... wolffd@0: 'int16'},{},mfilename, 'I, BW, or RGB',1); wolffd@0: I = varargin{1}; wolffd@0: wolffd@0: if nargin==2 wolffd@0: if isa(I,'int16') wolffd@0: eid = sprintf('Images:%s:invalidIndexedImage',mfilename); wolffd@0: msg1 = 'An indexed image can be uint8, uint16, double, single, or '; wolffd@0: msg2 = 'logical.'; wolffd@0: error(eid,'%s %s',msg1, msg2); wolffd@0: end wolffd@0: map = varargin{2}; wolffd@0: iptcheckinput(map,{'double'},{},mfilename,'MAP',1); wolffd@0: if ((size(map,1) == 1) && (prod(map) == numel(I))) wolffd@0: % MONTAGE(D,[M N P]) OBSOLETE wolffd@0: eid = sprintf('Images:%s:obsoleteSyntax',mfilename); wolffd@0: msg1 = 'MONTAGE(D,[M N P]) is an obsolete syntax.'; wolffd@0: msg2 = 'Use multidimensional arrays to represent multiframe images.'; wolffd@0: error(eid,'%s\n%s',msg1,msg2); wolffd@0: end wolffd@0: end