show_slices

PURPOSE ^

out_img = show_slices (img, levels ) show slices at levels of an

SYNOPSIS ^

function out_img= show_slices( img, levels )

DESCRIPTION ^

 out_img = show_slices (img, levels ) show slices at levels of an
             using a fast rendering algorithm
 img    = EIDORS image struct, or a array of structs
 out_img= matrix in the current colormap which we can use image(out_img);

 PARAMETERS:
  levels = Matrix [Lx3] of L image levels
           each row of the matrix specifies the intercepts
           of the slice on the x, y, z axis. To specify a z=2 plane
           parallel to the x,y: use levels= [inf,inf,2]
  
  if levels is [L x 5] then levels= [x,y,z,h,v] where,
           x,y,z specify the axes intercepts, and 
           h,v   specify the horizontal, vertical position
                 of that slice in the output image
 
 IMAGE PARAMETERS:
   img.show_slices.levels (same as above);
   img.show_slices.img_cols = number of columns in image
   img.show_slices.sep = number of pixels between the individual images
   img.calc_colours.npoints = pixel width/height to map to

 if levels is scalar, then make levels equispaced horizontal
          cuts through the object

 Show slices is roughly equivalent to:
   rimg = calc_slices(img,levels); 
   rimg = calc_colours(rimg,img); image(rimg);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function out_img= show_slices( img, levels )
0002 % out_img = show_slices (img, levels ) show slices at levels of an
0003 %             using a fast rendering algorithm
0004 % img    = EIDORS image struct, or a array of structs
0005 % out_img= matrix in the current colormap which we can use image(out_img);
0006 %
0007 % PARAMETERS:
0008 %  levels = Matrix [Lx3] of L image levels
0009 %           each row of the matrix specifies the intercepts
0010 %           of the slice on the x, y, z axis. To specify a z=2 plane
0011 %           parallel to the x,y: use levels= [inf,inf,2]
0012 %
0013 %  if levels is [L x 5] then levels= [x,y,z,h,v] where,
0014 %           x,y,z specify the axes intercepts, and
0015 %           h,v   specify the horizontal, vertical position
0016 %                 of that slice in the output image
0017 %
0018 % IMAGE PARAMETERS:
0019 %   img.show_slices.levels (same as above);
0020 %   img.show_slices.img_cols = number of columns in image
0021 %   img.show_slices.sep = number of pixels between the individual images
0022 %   img.calc_colours.npoints = pixel width/height to map to
0023 %
0024 % if levels is scalar, then make levels equispaced horizontal
0025 %          cuts through the object
0026 %
0027 % Show slices is roughly equivalent to:
0028 %   rimg = calc_slices(img,levels);
0029 %   rimg = calc_colours(rimg,img); image(rimg);
0030 
0031 % (C) 2005-2008 Andy Adler. License: GPL version 2 or version 3
0032 % $Id: show_slices.html 2819 2011-09-07 16:43:11Z aadler $
0033 
0034 if isstr(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0035 
0036 np = calc_colours('npoints');
0037 try   np = img(1).calc_colours.npoints;
0038 end
0039 
0040 sep = 0;
0041 try sep = img(1).show_slices.sep;
0042 end
0043 
0044 
0045 do_calc_slices = 0;
0046 try if strcmp(img(1).type,'image'); do_calc_slices= 1; end;end 
0047 
0048 if nargin<=1;
0049    try   levels = img(1).show_slices.levels
0050    catch levels = [];
0051    end
0052 end
0053 
0054 if isempty(levels) && do_calc_slices && size(img(1).fwd_model.nodes,2)==2
0055    levels= [Inf,Inf,0];
0056 end
0057 
0058 if size(levels,2) == 5
0059    spec_position= 1;
0060 elseif size(levels)== [1,1]
0061    if size(img(1).fwd_model.nodes,2) == 2 % Can't do horiz slices for 2D model
0062       eidors_msg('Can''t do horizontal slices for 2D model. Showing 2D slice');
0063       levels= [Inf,Inf,0];
0064       spec_position= 0;
0065    else
0066       zmax= max(img(1).fwd_model.nodes(:,3));
0067       zmin= min(img(1).fwd_model.nodes(:,3));
0068       levels = linspace(zmax,zmin, levels+2);
0069       levels = levels(2:end-1)';
0070       levels = [(1+0*levels)*[Inf,Inf], levels];
0071       spec_position= 0;
0072    end
0073 else
0074    spec_position= 0;
0075 end
0076 
0077 if do_calc_slices
0078    rimg= calc_slices( img, levels(:,1:3) );
0079 else
0080    rimg= img;
0081    np = size(rimg,1);
0082 end
0083 
0084 
0085 n_frames = size(rimg,3);
0086 n_levels = size(rimg,4);
0087 if spec_position %won't work for multiple image inputs
0088    img_cols = max( levels(:,4) );
0089    img_rows = max( levels(:,5) );
0090 else
0091    % vertical slices must be kept together
0092    % To nicely fill the image: img_cols ~ img_rows
0093    % Thus,  n_frames/vert_rows ~ vert_rows*n_levels;
0094    % or     vert_rows^2 ~ n_frames / n_levels
0095    vert_rows = ceil( sqrt(n_frames / n_levels) );
0096    try   img_cols = img(1).show_slices.img_cols;
0097    catch img_cols = ceil( n_frames/vert_rows );
0098    end
0099    img_rows = ceil(n_frames*n_levels/img_cols);
0100    img_rows = ceil(img_rows/n_levels)*n_levels; % Ensure divisible by n_levels
0101 end
0102 % here include the separation
0103 r_img = NaN*ones(img_rows*np + (img_rows-1)*sep, ...
0104     img_cols*np + (img_cols-1)*sep );
0105 
0106 idx= (-np:-1)+1;
0107 imno= 1;
0108 for img_no = 1:n_frames
0109    for lev_no = 1:n_levels
0110       if spec_position %won't work for multiple image inputs
0111          i_col= levels( lev_no, 4) + img_no -1;
0112          i_row= levels( lev_no, 5);
0113       else
0114          i_col= rem( img_no-1, img_cols) + 1;
0115          i_row= (ceil( img_no / img_cols) -1) * n_levels + lev_no ;
0116       end
0117 % disp([imno, vert_rows, img_cols, img_rows, img_no, lev_no, i_col, i_row]);
0118       r_img(i_row*np + idx + sep*(i_row-1), i_col*np + idx +sep*(i_col-1)) = rimg(:,:,img_no,lev_no);
0119       imno= imno + 1; 
0120    end
0121 end
0122 
0123 c_img = calc_colours( r_img, img);
0124 out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0125 
0126 
0127 image(out_img);
0128 axis('image');axis('off');axis('equal');
0129 
0130 if nargout==0; clear('out_img'); end
0131 
0132 
0133 function do_unit_test
0134    clf
0135 
0136    img=calc_jacobian_bkgnd(mk_common_model('a2c0',8)); 
0137    img.elem_data=rand(size(img.fwd_model.elems,1),1);
0138    subplot(3,4,1); show_slices(img) 
0139 
0140    img.calc_colours.npoints= 128;
0141    subplot(3,4,2); show_slices(img) 
0142 
0143    img.calc_colours.npoints= 32;
0144    img.elem_data=rand(size(img.fwd_model.elems,1),3);
0145    subplot(3,4,3); show_slices(img) 
0146 
0147    img.show_slices.img_cols= 1;
0148    subplot(3,4,4); show_slices(img) 
0149 
0150    imgn = rmfield(img,'elem_data');
0151    imgn.node_data=rand(size(img.fwd_model.nodes,1),1);
0152    subplot(3,4,5); show_slices(imgn) 
0153 
0154    img=calc_jacobian_bkgnd(mk_common_model('n3r2',32)); 
0155    img.calc_colours.npoints= 16;
0156    img.elem_data=rand(size(img.fwd_model.elems,1),1);
0157    subplot(3,4,6); show_slices(img,2) 
0158 
0159    img.elem_data=img.elem_data*[1:3];
0160    subplot(3,4,7); show_slices(img,2) 
0161 
0162    img.elem_data=img.elem_data(:,1:2);
0163    subplot(3,4,8); show_slices(img,[inf,inf,1;0,inf,inf;0,1,inf]);

Generated on Tue 09-Aug-2011 11:38:31 by m2html © 2005