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
          or output of CALC_SLICES (or equivalent multi-dimensional
          picture array to be processed by mk_mosaic
 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
   img.get_img_data.frame_select = which frames of image to display

 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);

 See also: CALC_SLICES, MK_MOSAIC

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 %          or output of CALC_SLICES (or equivalent multi-dimensional
0006 %          picture array to be processed by mk_mosaic
0007 % out_img= matrix in the current colormap which we can use image(out_img);
0008 %
0009 % PARAMETERS:
0010 %  levels = Matrix [Lx3] of L image levels
0011 %           each row of the matrix specifies the intercepts
0012 %           of the slice on the x, y, z axis. To specify a z=2 plane
0013 %           parallel to the x,y: use levels= [inf,inf,2]
0014 %
0015 %  if levels is [L x 5] then levels= [x,y,z,h,v] where,
0016 %           x,y,z specify the axes intercepts, and
0017 %           h,v   specify the horizontal, vertical position
0018 %                 of that slice in the output image
0019 %
0020 % IMAGE PARAMETERS:
0021 %   img.show_slices.levels (same as above);
0022 %   img.show_slices.img_cols = number of columns in image
0023 %   img.show_slices.sep = number of pixels between the individual images
0024 %   img.calc_colours.npoints = pixel width/height to map to
0025 %   img.get_img_data.frame_select = which frames of image to display
0026 %
0027 % if levels is scalar, then make levels equispaced horizontal
0028 %          cuts through the object
0029 %
0030 % Show slices is roughly equivalent to:
0031 %   rimg = calc_slices(img,levels);
0032 %   rimg = calc_colours(rimg,img); image(rimg);
0033 %
0034 % See also: CALC_SLICES, MK_MOSAIC
0035 
0036 % (C) 2005-2008 Andy Adler. License: GPL version 2 or version 3
0037 % $Id: show_slices.m 5303 2016-12-27 11:47:28Z aadler $
0038 
0039 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0040 
0041 sep = 0;
0042 try sep = img(1).show_slices.sep;
0043 end
0044 
0045 
0046 % TODO: because we wanted (back in 2005) to let show_slices
0047 % handle lots of different scenarios (calling with images and
0048 % without. It is now crufty ... and should be changed.
0049 do_calc_slices = 0;
0050 try if strcmp(img(1).type,'image'); do_calc_slices= 1; end;end 
0051 
0052 if nargin<=1;
0053    try   
0054        levels = img(1).show_slices.levels;
0055    catch
0056        levels = [];
0057    end
0058 end
0059 
0060 if isempty(levels) && do_calc_slices %&& size(img(1).fwd_model.nodes,2)==2
0061    levels= [Inf,Inf,0];
0062 end
0063 
0064 vh = [];
0065 if size(levels,2) == 5
0066    vh = levels(:,4:5);
0067    levels = levels(:,1:3);
0068 elseif size(levels)== [1,1]
0069    if size(img(1).fwd_model.nodes,2) == 2 % Can't do horiz slices for 2D model
0070       eidors_msg('Can''t do horizontal slices for 2D model. Showing 2D slice');
0071       levels= [Inf,Inf,0];
0072    else
0073       zmax= max(img(1).fwd_model.nodes(:,3));
0074       zmin= min(img(1).fwd_model.nodes(:,3));
0075       levels = linspace(zmax,zmin, levels+2);
0076       levels = levels(2:end-1)';
0077       levels = [(1+0*levels)*[Inf,Inf], levels];
0078    end
0079 end
0080 
0081 if do_calc_slices
0082    rimg= calc_slices( img, levels(:,1:3) );
0083 else
0084    rimg= img;
0085 end
0086 
0087 n_col = 0;
0088 try  n_col = img(1).show_slices.img_cols;
0089 end
0090 
0091 r_img = mk_mosaic(rimg, sep, vh, n_col);
0092 
0093 c_img = calc_colours( r_img, img);
0094 out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0095 
0096 
0097 image(out_img);
0098 axis image
0099 axis off
0100 axis equal
0101 axis tight
0102 
0103 if nargout==0; clear('out_img'); end
0104 
0105 function do_unit_test
0106    clf
0107 
0108    img=calc_jacobian_bkgnd(mk_common_model('a2t3',8)); 
0109    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0110    subplot(4,4,1); show_slices(img) 
0111 
0112    img.calc_colours.npoints= 128;
0113    subplot(4,4,2); show_slices(img) 
0114 
0115    img.calc_colours.npoints= 32;
0116    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1:3);
0117    subplot(4,4,3); show_slices(img) 
0118 
0119 
0120    img.show_slices.img_cols= 1;
0121    subplot(4,4,4); show_slices(img) 
0122 
0123    imgn = rmfield(img,'elem_data');
0124    imgn.node_data=toeplitz(1:size(img.fwd_model.nodes,1),1);
0125 
0126    img.elem_data = img.elem_data(:,1);
0127    img.fwd_model.mdl_slice_mapper.npx = 10;
0128    img.fwd_model.mdl_slice_mapper.npy = 20;
0129    img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0130    subplot(4,4,5); show_slices(img);
0131 
0132    img.elem_data = img.elem_data(:,1);
0133    img.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0134    img.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0135    img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0136    subplot(4,4,6); show_slices(img);
0137 
0138    subplot(4,4,7); show_slices(imgn) 
0139 
0140    imgn.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0141    imgn.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0142    imgn.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0143    subplot(4,4,8); show_slices(imgn) 
0144 
0145 
0146 % 3D images
0147    img=calc_jacobian_bkgnd(mk_common_model('n3r2',[16,2])); 
0148    img.calc_colours.npoints= 16;
0149    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0150    subplot(4,4,9); show_slices(img,2) 
0151 
0152 
0153    img.elem_data=img.elem_data*[1:3];
0154    subplot(4,4,10); show_slices(img,2) 
0155 
0156    img.elem_data=img.elem_data(:,1:2);
0157    subplot(4,4,11); show_slices(img,[inf,inf,1;0,inf,inf;0,1,inf]);
0158 
0159    img.show_slices.sep = 5;
0160    img.fwd_model.mdl_slice_mapper.x_pts = linspace(-1,1,20);
0161    img.fwd_model.mdl_slice_mapper.y_pts = linspace(-1,1,30);
0162    img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0163 
0164    subplot(4,4,12); show_slices(img,2) 
0165 
0166 
0167    img.elem_data = img.elem_data(:,1);
0168    levels=[inf,inf,1,1,1;
0169            0,inf,inf,2,1;
0170            0,1,inf,3,1];
0171    subplot(4,4,13); show_slices(img,levels) 
0172 
0173    levels=[inf,inf,1,1,1;
0174            0,inf,inf,2,2;
0175            0,1,inf,  1,3];
0176    subplot(4,4,14); show_slices(img,levels) 
0177 
0178    img.elem_data = img.elem_data(:,[1,1]);
0179    levels=[inf,inf,1,1,1;
0180            0,inf,inf,2,1;
0181            0,1,inf,  3,1];
0182    subplot(4,4,15); show_slices(img,levels) 
0183    
0184    m = calc_slices(img,levels);
0185    subplot(4,4,16); show_slices(m) 
0186    
0187

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005