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
   img.show_slices.axes_msm = use mdl_slice_mapper for x,y axes
        %% Example
        img.fwd_model.mdl_slice_mapper = struct('level',[inf,0,inf], ...
          'x_pts', linspace(-2,2,50), 'y_pts',linspace(2,10,100));
        img.show_slices.axes_msm = true; show_slices(img);
   img.show_slices.contour_levels = true => Do a contour on the image
   img.show_slices.contour_levels = #    => Put this many contour lines
   img.show_slices.contour_levels = vector => Put contours at these locations
   img.show_slices.contour_properties => e.g. {'Color',[0,0,0],'LineWidth',2}

 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 %   img.show_slices.axes_msm = use mdl_slice_mapper for x,y axes
0027 %        %% Example
0028 %        img.fwd_model.mdl_slice_mapper = struct('level',[inf,0,inf], ...
0029 %          'x_pts', linspace(-2,2,50), 'y_pts',linspace(2,10,100));
0030 %        img.show_slices.axes_msm = true; show_slices(img);
0031 %   img.show_slices.contour_levels = true => Do a contour on the image
0032 %   img.show_slices.contour_levels = #    => Put this many contour lines
0033 %   img.show_slices.contour_levels = vector => Put contours at these locations
0034 %   img.show_slices.contour_properties => e.g. {'Color',[0,0,0],'LineWidth',2}
0035 %
0036 % if levels is scalar, then make levels equispaced horizontal
0037 %          cuts through the object
0038 %
0039 % Show slices is roughly equivalent to:
0040 %   rimg = calc_slices(img,levels);
0041 %   rimg = calc_colours(rimg,img); image(rimg);
0042 %
0043 % See also: CALC_SLICES, MK_MOSAIC
0044 
0045 % (C) 2005-2008 Andy Adler. License: GPL version 2 or version 3
0046 % $Id: show_slices.m 6046 2019-12-31 20:10:42Z aadler $
0047 
0048 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0049 
0050 sep = 0;
0051 try sep = img(1).show_slices.sep;
0052 end
0053 
0054 
0055 % TODO: because we wanted (back in 2005) to let show_slices
0056 % handle lots of different scenarios (calling with images and
0057 % without. It is now crufty ... and should be changed.
0058 do_calc_slices = 0;
0059 try if strcmp(img(1).type,'image'); do_calc_slices= 1; end;end 
0060 
0061 if nargin<=1;
0062    try   
0063        levels = img(1).show_slices.levels;
0064    catch
0065        levels = [];
0066    end
0067 end
0068 
0069 if isempty(levels) && do_calc_slices %&& size(img(1).fwd_model.nodes,2)==2
0070    levels= [Inf,Inf,0];
0071 end
0072 
0073 vh = [];
0074 if size(levels,2) == 5
0075    vh = levels(:,4:5);
0076    levels = levels(:,1:3);
0077 elseif size(levels)== [1,1]
0078    if size(img(1).fwd_model.nodes,2) == 2 % Can't do horiz slices for 2D model
0079       eidors_msg('Can''t do horizontal slices for 2D model. Showing 2D slice');
0080       levels= [Inf,Inf,0];
0081    else
0082       zmax= max(img(1).fwd_model.nodes(:,3));
0083       zmin= min(img(1).fwd_model.nodes(:,3));
0084       levels = linspace(zmax,zmin, levels+2);
0085       levels = levels(2:end-1)';
0086       levels = [(1+0*levels)*[Inf,Inf], levels];
0087    end
0088 end
0089 
0090 if do_calc_slices
0091    rimg= calc_slices( img, levels(:,1:3) );
0092 else
0093    rimg= img;
0094 end
0095 % Eventualy we need to add a filter control to do this -aa'19
0096 %if 0
0097 %   filt = ones(5);
0098 %    filt = conv2(filt,filt);
0099 %   rnimg = rimg;
0100 %   rimg(isnan(rimg)) = 0;
0101 %   rimg = conv2(rimg, filt,'same') / sum(filt(:));
0102 %   rimg(isnan(rnimg)) = NaN;
0103 %end
0104 
0105 n_col = 0;
0106 try  n_col = img(1).show_slices.img_cols;
0107 end
0108 
0109 r_img = mk_mosaic(rimg, sep, vh, n_col);
0110 
0111 c_img = calc_colours( r_img, img);
0112 out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0113 
0114 
0115 axes_msm = false;
0116 try axes_msm = img.show_slices.axes_msm; end
0117 
0118 if ~axes_msm
0119    image(out_img);
0120    axis image
0121    axis off
0122    axis equal
0123    axis tight
0124 else
0125    msm = img.fwd_model.mdl_slice_mapper;
0126    image(msm.x_pts, msm.y_pts, out_img);
0127    set(gca,'Ydir','normal');
0128 end
0129 
0130 % Do a contour plot?
0131 if isfield(img(1),'show_slices') && isfield(img(1).show_slices,'contour_levels');
0132    clevs = img.show_slices.contour_levels;
0133    if isfield(img.show_slices,'contour_properties');
0134       contour_properties = img.show_slices.contour_properties;
0135    else
0136       contour_properties = {'Color',[0.2,0.2,0.3]};
0137    end
0138 
0139    if ~axes_msm;
0140       msm.x_pts = 1:size(rimg,2);
0141       msm.y_pts = 1:size(rimg,1);
0142    end
0143    ish= ishold;
0144    if isnumeric(clevs)
0145       if ~ish; hold on; end 
0146       contour(msm.x_pts, msm.y_pts, rimg, clevs, contour_properties{:});
0147       if ~ish; hold off; end 
0148    elseif clevs % true but not numeric
0149       if ~ish; hold on; end 
0150       contour(msm.x_pts, msm.y_pts, rimg, contour_properties{:});
0151       if ~ish; hold off; end 
0152    else
0153       error('img.show_slices.contour_levels parameter not understood');
0154    end
0155 end
0156 
0157 if nargout==0; clear('out_img'); end
0158 
0159 function do_unit_test
0160    clf; sp=0;
0161 
0162    img=calc_jacobian_bkgnd(mk_common_model('a2t3',8)); 
0163    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0164    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0165 
0166    img.calc_colours.npoints= 128;
0167    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0168 
0169    img.calc_colours.npoints= 32;
0170    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1:3);
0171    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0172 
0173 
0174    img.show_slices.img_cols= 1;
0175    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0176 
0177    imgn = rmfield(img,'elem_data');
0178    imgn.node_data=toeplitz(1:size(img.fwd_model.nodes,1),1);
0179 
0180    img.elem_data = img.elem_data(:,1);
0181    img.fwd_model.mdl_slice_mapper.npx = 10;
0182    img.fwd_model.mdl_slice_mapper.npy = 20;
0183    img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0184    sp=sp+1;subplot(4,5,sp); show_slices(img);
0185 
0186    img.elem_data = img.elem_data(:,1);
0187    img.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0188    img.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0189    img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0190    sp=sp+1;subplot(4,5,sp); show_slices(img);
0191 
0192    sp=sp+1;subplot(4,5,sp); show_slices(imgn) 
0193 
0194    imgn.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0195    imgn.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0196    imgn.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0197    sp=sp+1;subplot(4,5,sp); show_slices(imgn) 
0198 
0199 
0200 % 3D images
0201    img=calc_jacobian_bkgnd(mk_common_model('n3r2',[16,2])); 
0202    img.calc_colours.npoints= 16;
0203    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0204    sp=sp+1;subplot(4,5,sp); show_slices(img,2) 
0205 
0206 
0207    img.elem_data=img.elem_data*[1:3];
0208    sp=sp+1;subplot(4,5,sp); show_slices(img,2) 
0209 
0210    img.elem_data=img.elem_data(:,1:2);
0211    sp=sp+1;subplot(4,5,sp); show_slices(img,[inf,inf,1;0,inf,inf;0,1,inf]);
0212 
0213    img.show_slices.sep = 5;
0214    img.fwd_model.mdl_slice_mapper.x_pts = linspace(-1,1,20);
0215    img.fwd_model.mdl_slice_mapper.y_pts = linspace(-1,1,30);
0216    img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0217 
0218    sp=sp+1;subplot(4,5,sp); show_slices(img,2) 
0219 
0220 
0221    img.elem_data = img.elem_data(:,1);
0222    levels=[inf,inf,1,1,1;
0223            0,inf,inf,2,1;
0224            0,1,inf,3,1];
0225    sp=sp+1;subplot(4,5,sp); show_slices(img,levels) 
0226 
0227    levels=[inf,inf,1,1,1;
0228            0,inf,inf,2,2;
0229            0,1,inf,  1,3];
0230    sp=sp+1;subplot(4,5,sp); show_slices(img,levels) 
0231 
0232    img.elem_data = img.elem_data(:,[1,1]);
0233    levels=[inf,inf,1,1,1;
0234            0,inf,inf,2,1;
0235            0,1,inf,  3,1];
0236    sp=sp+1;subplot(4,5,sp); show_slices(img,levels) 
0237    
0238    m = calc_slices(img,levels);
0239    sp=sp+1;subplot(4,5,sp); show_slices(m) 
0240    
0241    img.elem_data = img.elem_data(:,1);
0242    img.show_slices.contour_levels = true;
0243    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0244 
0245    img.fwd_model.mdl_slice_mapper = struct('level',[inf,inf,1], ...
0246      'x_pts', linspace(-1,1,50), 'y_pts',linspace(-2,2,100));
0247    img.show_slices.axes_msm = true;
0248    img.show_slices.contour_properties = {'LineWidth',2};
0249    img.show_slices.contour_levels = 1:300;
0250    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0251

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