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:

SUBFUNCTIONS ^

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 6335 2022-04-21 20:43:32Z bgrychtol $
0023 
0024 if nargin==1 && ischar(rimg) && strcmp(rimg, 'UNIT_TEST'), do_unit_test, return, end
0025 
0026 % jnk so that matab doesn't put larger dims in npy
0027 [npy,npx,jnk] = size(rimg);
0028 n_frames = size(rimg,3);
0029 n_levels = size(rimg,4);
0030 
0031 if nargin < 2
0032     sep = 0;
0033 end
0034 if nargin < 3
0035     vh = [];
0036 end
0037 if nargin < 4 
0038     n_col = 0;
0039 end
0040 vert_rows = 0;
0041 if nargin > 2 && ~isempty(vh)
0042     img_cols = n_frames * max( vh(:,1) );
0043     img_rows = max( vh(:,2) );
0044 else
0045     % vertical slices must be kept together
0046     % To nicely fill the image: img_cols ~ img_rows
0047     % Thus,  n_frames/vert_rows ~ vert_rows*n_levels;
0048     % or     vert_rows^2 ~ n_frames / n_levels
0049     vert_rows = ceil( sqrt(n_frames / n_levels) );
0050     if n_col > 0
0051         img_cols = n_col;
0052     else 
0053         img_cols = ceil( n_frames/vert_rows );
0054     end
0055     img_rows = ceil(n_frames*n_levels/img_cols);
0056     img_rows = ceil(img_rows/n_levels)*n_levels; % Ensure divisible by n_levels
0057 end
0058 % here include the separation
0059 r_img = NaN*ones(img_rows*npy + (img_rows-1)*sep, ...
0060                  img_cols*npx + (img_cols-1)*sep );
0061 
0062 idxx= (-npx:-1)+1;
0063 idxy= (-npy:-1)+1;
0064 imno= 1;
0065 for img_no = 1:n_frames
0066    for lev_no = 1:n_levels
0067       if ~isempty(vh) %won't work for multiple image inputs
0068          i_col= n_frames*(vh( lev_no, 1)-1) + img_no;
0069          i_row= vh( lev_no, 2);
0070       else
0071          i_col= rem( img_no-1, img_cols) + 1;
0072          i_row= (ceil( img_no / img_cols) -1) * n_levels + lev_no ;
0073       end
0074 %       disp([imno, vert_rows, img_cols, img_rows, img_no, lev_no, i_col, i_row]);
0075       r_img(i_row*npy + idxy + sep*(i_row-1), ...
0076             i_col*npx + idxx + sep*(i_col-1)) = rimg(:,:,img_no,lev_no);
0077       imno= imno + 1; 
0078    end
0079 end
0080 
0081 function do_unit_test
0082    img=calc_jacobian_bkgnd(mk_common_model('n3r2',[16,2]));
0083    img.calc_colours.npoints= 16;
0084    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0085    img.elem_data = img.elem_data(:,[1,1]);
0086    levels=[inf,inf,1,1,1;
0087            0,inf,inf,2,1;
0088            0,1,inf,  3,1];
0089    rimg= calc_slices( img, levels(:,1:3) );
0090    msk = mk_mosaic(rimg, 0, levels(:,4:5));
0091    subplot(3,1,1)
0092    imagesc(msk), axis equal tight
0093    
0094    msk = mk_mosaic(rimg);
0095    subplot(3,1,2)
0096    imagesc(msk), axis equal tight
0097

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005