annotate toolboxes/FullBNT-1.0.7/KPMtools/montageKPM.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 h = montageKPM(arg)
Daniel@0 2 % montageKPM is like the built-in montage, but assumes input is MxNxK or filenames
Daniel@0 3 %
Daniel@0 4 % Converts patches (y,x,i) into patches(y,x,1,i)
Daniel@0 5 % Also, adds a black border aroudn them
Daniel@0 6
Daniel@0 7 if iscell(arg)
Daniel@0 8 h= montageFilenames(arg);
Daniel@0 9 else
Daniel@0 10 nr = size(arg,1); nc = size(arg,2); Npatches = size(arg,3);
Daniel@0 11 patchesColor = reshape(arg, [nr nc 1 Npatches]);
Daniel@0 12 patchesColor = patchesColor ./ max(patchesColor(:));
Daniel@0 13
Daniel@0 14 if 1
Daniel@0 15 %put a black border around them for display purposes
Daniel@0 16 border = 5;
Daniel@0 17 bgColor = ones(1,1,class(patchesColor));
Daniel@0 18 patchesColorBig = bgColor*ones(nr+2*border, nc+2*border, 1, Npatches, class(patchesColor));
Daniel@0 19 %patchesColorBig = zeros(nr+2*border, nc+2*border, 1, Npatches, class(patchesColor));
Daniel@0 20 patchesColorBig(border+1:end-border, border+1:end-border, :, :) = patchesColor;
Daniel@0 21 else
Daniel@0 22 patchesColorBig = patchesColor;
Daniel@0 23 end
Daniel@0 24 montage(patchesColorBig)
Daniel@0 25
Daniel@0 26 end
Daniel@0 27
Daniel@0 28 %%%%%%%%%%%%%
Daniel@0 29
Daniel@0 30 function h = montageFilenames(filenames)
Daniel@0 31
Daniel@0 32 %[nRows, nCols, nBands, nFrames] = size(a);
Daniel@0 33
Daniel@0 34 % Estimate nMontageColumns and nMontageRows given the desired ratio of
Daniel@0 35 % Columns to Rows to be one (square montage).
Daniel@0 36 aspectRatio = 1;
Daniel@0 37 nMontageCols = sqrt(aspectRatio * nRows * nFrames / nCols);
Daniel@0 38
Daniel@0 39 % Make sure montage rows and columns are integers. The order in the adjustment
Daniel@0 40 % matters because the montage image is created horizontally across columns.
Daniel@0 41 nMontageCols = ceil(nMontageCols);
Daniel@0 42 nMontageRows = ceil(nFrames / nMontageCols);
Daniel@0 43
Daniel@0 44 % Create the montage image.
Daniel@0 45 b = a(1,1); % to inherit type
Daniel@0 46 b(1,1) = 0; % from a
Daniel@0 47 b = repmat(b, [nMontageRows*nRows, nMontageCols*nCols, nBands, 1]);
Daniel@0 48
Daniel@0 49 rows = 1 : nRows;
Daniel@0 50 cols = 1 : nCols;
Daniel@0 51
Daniel@0 52 for i = 0:nMontageRows-1
Daniel@0 53 for j = 0:nMontageCols-1,
Daniel@0 54 k = j + i * nMontageCols + 1;
Daniel@0 55 if k <= nFrames
Daniel@0 56 b(rows + i * nRows, cols + j * nCols, :) = a(:,:,:,k);
Daniel@0 57 else
Daniel@0 58 break;
Daniel@0 59 end
Daniel@0 60 end
Daniel@0 61 end
Daniel@0 62
Daniel@0 63 if isempty(cm)
Daniel@0 64 hh = imshow(b);
Daniel@0 65 else
Daniel@0 66 hh = imshow(b,cm);
Daniel@0 67 end
Daniel@0 68
Daniel@0 69 if nargout > 0
Daniel@0 70 h = hh;
Daniel@0 71 end
Daniel@0 72
Daniel@0 73 %--------------------------------------------------------------
Daniel@0 74 %Parse Inputs Function
Daniel@0 75
Daniel@0 76 function [I,map] = parse_inputs(varargin)
Daniel@0 77
Daniel@0 78 % initialize variables
Daniel@0 79 map = [];
Daniel@0 80
Daniel@0 81 iptchecknargin(1,2,nargin,mfilename);
Daniel@0 82 iptcheckinput(varargin{1},{'uint8' 'double' 'uint16' 'logical' 'single' ...
Daniel@0 83 'int16'},{},mfilename, 'I, BW, or RGB',1);
Daniel@0 84 I = varargin{1};
Daniel@0 85
Daniel@0 86 if nargin==2
Daniel@0 87 if isa(I,'int16')
Daniel@0 88 eid = sprintf('Images:%s:invalidIndexedImage',mfilename);
Daniel@0 89 msg1 = 'An indexed image can be uint8, uint16, double, single, or ';
Daniel@0 90 msg2 = 'logical.';
Daniel@0 91 error(eid,'%s %s',msg1, msg2);
Daniel@0 92 end
Daniel@0 93 map = varargin{2};
Daniel@0 94 iptcheckinput(map,{'double'},{},mfilename,'MAP',1);
Daniel@0 95 if ((size(map,1) == 1) && (prod(map) == numel(I)))
Daniel@0 96 % MONTAGE(D,[M N P]) OBSOLETE
Daniel@0 97 eid = sprintf('Images:%s:obsoleteSyntax',mfilename);
Daniel@0 98 msg1 = 'MONTAGE(D,[M N P]) is an obsolete syntax.';
Daniel@0 99 msg2 = 'Use multidimensional arrays to represent multiframe images.';
Daniel@0 100 error(eid,'%s\n%s',msg1,msg2);
Daniel@0 101 end
Daniel@0 102 end