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