about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/KPMtools/montageKPM.m
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/KPMtools/montageKPM.m
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning.

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