mk_mosaic

PURPOSE ^

MK_MOSAIC Arrange multidimensional image matrix for display.

SYNOPSIS ^

function r_img = mk_mosaic(rimg, sep, vh, n_col)

DESCRIPTION ^

MK_MOSAIC Arrange multidimensional image matrix for display.
  M = MK_MOSAIC(rimg, sep, vh, n_col)
  Input:
   rimg - an HxWxN or HxWxNxM array of pictures of size HxW
   sep  - (optional) spacing between adjecent pictures (in pixels)
          default: 0
   vh   - an Mx2 array of positions for individual HxWxN blocks 
          (N can be 1) default: []
   n_col- force number of columns, otherwise adjusted to create a
          roughly square output

 Output: A 2D array suitable for display with e.g. IMAGESC
 
 This function is primarily used by SHOW_SLICES, but can also be called
 directly.

 See also: SHOW_SLICES

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function r_img = mk_mosaic(rimg, sep, vh, n_col)
0002 %MK_MOSAIC Arrange multidimensional image matrix for display.
0003 %  M = MK_MOSAIC(rimg, sep, vh, n_col)
0004 %  Input:
0005 %   rimg - an HxWxN or HxWxNxM array of pictures of size HxW
0006 %   sep  - (optional) spacing between adjecent pictures (in pixels)
0007 %          default: 0
0008 %   vh   - an Mx2 array of positions for individual HxWxN blocks
0009 %          (N can be 1) default: []
0010 %   n_col- force number of columns, otherwise adjusted to create a
0011 %          roughly square output
0012 %
0013 % Output: A 2D array suitable for display with e.g. IMAGESC
0014 %
0015 % This function is primarily used by SHOW_SLICES, but can also be called
0016 % directly.
0017 %
0018 % See also: SHOW_SLICES
0019 
0020 % (C) 2005-2012 Andy Adler and Bartlomiej Grychtol
0021 % License: GPL v2 or v3.
0022 % $Id: mk_mosaic.m 3491 2012-07-04 09:41:05Z aadler $
0023 
0024 % jnk so that matab doesn't put larger dims in npy
0025 [npy,npx,jnk] = size(rimg);
0026 n_frames = size(rimg,3);
0027 n_levels = size(rimg,4);
0028 
0029 if nargin < 2
0030     sep = 0;
0031 end
0032 if nargin < 3
0033     vh = [];
0034 end
0035 if nargin < 4 
0036     n_col = 0;
0037 end
0038 if nargin > 2 && ~isempty(vh)
0039     img_cols = max( vh(:,1) );
0040     img_rows = max( vh(:,2) );
0041 else
0042     % vertical slices must be kept together
0043     % To nicely fill the image: img_cols ~ img_rows
0044     % Thus,  n_frames/vert_rows ~ vert_rows*n_levels;
0045     % or     vert_rows^2 ~ n_frames / n_levels
0046     vert_rows = ceil( sqrt(n_frames / n_levels) );
0047     if n_col > 0
0048         img_cols = n_col;
0049     else 
0050         img_cols = ceil( n_frames/vert_rows );
0051     end
0052     img_rows = ceil(n_frames*n_levels/img_cols);
0053     img_rows = ceil(img_rows/n_levels)*n_levels; % Ensure divisible by n_levels
0054 end
0055 % here include the separation
0056 r_img = NaN*ones(img_rows*npy + (img_rows-1)*sep, ...
0057                  img_cols*npx + (img_cols-1)*sep );
0058 
0059 idxx= (-npx:-1)+1;
0060 idxy= (-npy:-1)+1;
0061 imno= 1;
0062 for img_no = 1:n_frames
0063    for lev_no = 1:n_levels
0064       if ~isempty(vh) %won't work for multiple image inputs
0065          i_col= vh( lev_no, 1) + img_no -1;
0066          i_row= vh( lev_no, 2);
0067       else
0068          i_col= rem( img_no-1, img_cols) + 1;
0069          i_row= (ceil( img_no / img_cols) -1) * n_levels + lev_no ;
0070       end
0071 % disp([imno, vert_rows, img_cols, img_rows, img_no, lev_no, i_col, i_row]);
0072       r_img(i_row*npy + idxy + sep*(i_row-1), ...
0073             i_col*npx + idxx + sep*(i_col-1)) = rimg(:,:,img_no,lev_no);
0074       imno= imno + 1; 
0075    end
0076 end

Generated on Tue 31-Dec-2019 17:03:26 by m2html © 2005