show_slices

PURPOSE ^

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

SYNOPSIS ^

function out_img= show_slices( img, levels, vh )

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 = any level defintion accepted by level_model_slice
  vh     = [Lx2] matrix specifying the horizontal (column), vertical (row)
           position of each 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.show_slices.do_colourbar = draw a colourbar (via calc_colours)
   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}
   img.calc_slices.filter => e.g. conv2(ones(5),ones(5))/5^4   

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

 Deprecated interface:
  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

 See also: LEVEL_MODEL_SLICE, CALC_SLICES, MK_MOSAIC, CALC_COLOURS

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function out_img= show_slices( img, levels, vh )
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 = any level defintion accepted by level_model_slice
0011 %  vh     = [Lx2] matrix specifying the horizontal (column), vertical (row)
0012 %           position of each slice in the output image
0013 %
0014 % IMAGE PARAMETERS:
0015 %   img.show_slices.levels (same as above);
0016 %   img.show_slices.img_cols = number of columns in image
0017 %   img.show_slices.sep = number of pixels between the individual images
0018 %   img.show_slices.do_colourbar = draw a colourbar (via calc_colours)
0019 %   img.calc_colours.npoints = pixel width/height to map to
0020 %   img.get_img_data.frame_select = which frames of image to display
0021 %   img.show_slices.axes_msm = use mdl_slice_mapper for x,y axes
0022 %        %% Example
0023 %        img.fwd_model.mdl_slice_mapper = struct('level',[inf,0,inf], ...
0024 %          'x_pts', linspace(-2,2,50), 'y_pts',linspace(2,10,100));
0025 %        img.show_slices.axes_msm = true; show_slices(img);
0026 %   img.show_slices.contour_levels = true => Do a contour on the image
0027 %   img.show_slices.contour_levels = #    => Put this many contour lines
0028 %   img.show_slices.contour_levels = vector => Put contours at these locations
0029 %   img.show_slices.contour_properties => e.g. {'Color',[0,0,0],'LineWidth',2}
0030 %   img.calc_slices.filter => e.g. conv2(ones(5),ones(5))/5^4
0031 %
0032 % Show slices is roughly equivalent to:
0033 %   rimg = calc_slices(img,levels);
0034 %   rimg = calc_colours(rimg,img); image(rimg);
0035 %
0036 % Deprecated interface:
0037 %  if levels is [L x 5] then levels= [x,y,z,h,v] where,
0038 %           x,y,z specify the axes intercepts, and
0039 %           h,v   specify the horizontal, vertical position
0040 %                 of that slice in the output image
0041 %
0042 % See also: LEVEL_MODEL_SLICE, CALC_SLICES, MK_MOSAIC, CALC_COLOURS
0043 
0044 % (C) 2005-2008 Andy Adler. License: GPL version 2 or version 3
0045 % $Id: show_slices.m 6337 2022-04-21 20:47:06Z bgrychtol $
0046 
0047 if ischar(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0048 
0049 sep = 0;
0050 try sep = img(1).show_slices.sep;
0051 end
0052 
0053 
0054 % TODO: because we wanted (back in 2005) to let show_slices
0055 % handle lots of different scenarios (calling with images and
0056 % without. It is now crufty ... and should be changed.
0057 do_calc_slices = 0;
0058 try if strcmp(img(1).type,'image'); do_calc_slices= 1; end;end 
0059 
0060 if nargin<=1;
0061    try   
0062        levels = img(1).show_slices.levels;
0063    catch
0064        levels = [];
0065    end
0066 end
0067 
0068 if isempty(levels) && do_calc_slices %&& size(img(1).fwd_model.nodes,2)==2
0069    levels= [Inf,Inf,0];
0070 end
0071 
0072 if nargin < 3
0073     vh = [];
0074 end
0075 if isempty(vh) && isnumeric(levels) && size(levels,2) == 5
0076    vh = levels(:,4:5);
0077    levels = levels(:,1:3);
0078    warning('EIDORS:DeprecatedInterface', ...
0079     'Specifing 5-element level is deprecated and will cause an error in a future release.');
0080 end
0081 
0082 if do_calc_slices
0083    rimg= calc_slices( img, levels );
0084 else
0085    rimg= img;
0086    if isstruct(levels)
0087        img = levels;
0088        levels = [];
0089    end
0090 end
0091 % Eventualy we need to add a filter control to do this -aa'19
0092 %% This is replaced with calc_slices.filter
0093 %if 0
0094 %   filt = ones(5);
0095 %    filt = conv2(filt,filt);
0096 %   rnimg = rimg;
0097 %   rimg(isnan(rimg)) = 0;
0098 %   rimg = conv2(rimg, filt,'same') / sum(filt(:));
0099 %   rimg(isnan(rnimg)) = NaN;
0100 %end
0101 
0102 n_col = 0;
0103 try  n_col = img(1).show_slices.img_cols;
0104 end
0105 
0106 r_img = mk_mosaic(rimg, sep, vh, n_col);
0107 
0108 c_img = calc_colours( r_img, img);
0109 out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0110 
0111 
0112 axes_msm = false;
0113 try axes_msm = img.show_slices.axes_msm; end
0114 
0115 if ~axes_msm
0116    image(out_img);
0117    axis image
0118    axis off
0119 else
0120    pts = mdl_slice_mapper(img.fwd_model,'get_points');
0121    msm.x_pts = pts{1}; msm.y_pts = pts{2};
0122    image(msm.x_pts, msm.y_pts, out_img);
0123    set(gca,'Ydir','normal');
0124 end
0125 axis equal
0126 axis tight
0127 
0128 do_colourbar = false;
0129 try do_colourbar = img.show_slices.do_colourbar; end
0130 if do_colourbar
0131     calc_colours( r_img, img, 1);
0132 end
0133 
0134 % Do a contour plot?
0135 if isfield(img(1),'show_slices') && isfield(img(1).show_slices,'contour_levels');
0136    clevs = img.show_slices.contour_levels;
0137    if isfield(img.show_slices,'contour_properties');
0138       contour_properties = img.show_slices.contour_properties;
0139    else
0140       contour_properties = {'Color',[0.2,0.2,0.3]};
0141    end
0142 
0143    if ~axes_msm;
0144       msm.x_pts = 1:size(rimg,2);
0145       msm.y_pts = 1:size(rimg,1);
0146    end
0147    ish= ishold;
0148    if isnumeric(clevs)
0149       if ~ish; hold on; end 
0150       contour(msm.x_pts, msm.y_pts, rimg, clevs, contour_properties{:});
0151       if ~ish; hold off; end 
0152    elseif clevs % true but not numeric
0153       if ~ish; hold on; end 
0154       contour(msm.x_pts, msm.y_pts, rimg, contour_properties{:});
0155       if ~ish; hold off; end 
0156    else
0157       error('img.show_slices.contour_levels parameter not understood');
0158    end
0159 end
0160 
0161 if nargout==0; clear('out_img'); end
0162 
0163 function do_unit_test
0164    clf; sp=0;
0165    %1
0166    img=calc_jacobian_bkgnd(mk_common_model('a2t3',8)); 
0167    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0168    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0169    %2
0170    img.calc_colours.npoints= 128;
0171    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0172    %3
0173    img.calc_colours.npoints= 32;
0174    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1:3);
0175    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0176 
0177    %4
0178    img.show_slices.img_cols= 1;
0179    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0180 
0181    %5
0182    imgn = rmfield(img,'elem_data');
0183    imgn.node_data=toeplitz(1:size(img.fwd_model.nodes,1),1);
0184 
0185    img.elem_data = img.elem_data(:,1);
0186    img.fwd_model.mdl_slice_mapper.npx = 10;
0187    img.fwd_model.mdl_slice_mapper.npy = 20;
0188    img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0189    sp=sp+1;subplot(4,5,sp); show_slices(img);
0190 
0191    %6
0192    img.elem_data = img.elem_data(:,1);
0193    img.fwd_model.mdl_slice_mapper = rmfield(img.fwd_model.mdl_slice_mapper, {'npx','npy'});
0194    img.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0195    img.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0196    img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0197    sp=sp+1;subplot(4,5,sp); show_slices(img);
0198 
0199    %7
0200    sp=sp+1;subplot(4,5,sp); show_slices(imgn) 
0201 
0202    %8
0203    imgn.fwd_model.mdl_slice_mapper.x_pts = linspace(-100,100,20);
0204    imgn.fwd_model.mdl_slice_mapper.y_pts = linspace(-150,150,30);
0205    imgn.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0206    sp=sp+1;subplot(4,5,sp); show_slices(imgn) 
0207 
0208 
0209 % 3D images
0210    %9
0211    img=calc_jacobian_bkgnd(mk_common_model('n3r2',[16,2])); 
0212    img.calc_colours.npoints= 16;
0213    img.elem_data=toeplitz(1:size(img.fwd_model.elems,1),1);
0214    sp=sp+1;subplot(4,5,sp); show_slices(img,2) 
0215 
0216    %10
0217    img.elem_data=img.elem_data*[1:3];
0218    sp=sp+1;subplot(4,5,sp); show_slices(img,2) 
0219 
0220    %11
0221    img.elem_data=img.elem_data(:,1:2);
0222    sp=sp+1;subplot(4,5,sp); show_slices(img,[inf,inf,1;0,inf,inf;0,1,inf]);
0223 
0224    %12
0225    img.show_slices.sep = 5;
0226    img.fwd_model.mdl_slice_mapper.x_pts = linspace(-1,1,20);
0227    img.fwd_model.mdl_slice_mapper.y_pts = linspace(-1,1,30);
0228    img.fwd_model.mdl_slice_mapper.level = [inf,inf,0];
0229 
0230    sp=sp+1;subplot(4,5,sp); show_slices(img,2) 
0231 
0232    %13
0233    img.fwd_model = rmfield(img.fwd_model, 'mdl_slice_mapper');
0234    img.elem_data = img.elem_data(:,1);
0235    levels=[inf,inf,1,1,1;
0236            0,inf,inf,2,1;
0237            0,1,inf,3,1];
0238    sp=sp+1;subplot(4,5,sp); show_slices(img,levels) 
0239 
0240    %14
0241    levels=[inf,inf,1,1,1;
0242            0,inf,inf,2,2;
0243            0,1,inf,  1,3];
0244    sp=sp+1;subplot(4,5,sp); show_slices(img,levels) 
0245 
0246    %15
0247    img.elem_data = img.elem_data * [1,2];
0248    levels=[inf,inf,1,1,1;
0249            0,inf,inf,2,1;
0250            0,1,inf,  3,1];
0251    sp=sp+1;subplot(4,5,sp); show_slices(img,levels) 
0252    
0253    %16
0254    sp=sp+1;subplot(4,5,sp); show_slices(img,levels(:,1:3),levels(:,4:5)) 
0255    
0256    %17
0257    m = calc_slices(img,levels(:,1:3));
0258    sp=sp+1;subplot(4,5,sp); show_slices(m) 
0259    
0260    %18
0261    img.elem_data = img.elem_data(:,1);
0262    img.show_slices.contour_levels = true;
0263    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0264 
0265    %19
0266    img.fwd_model.mdl_slice_mapper = struct('level',[inf,inf,1], ...
0267      'x_pts', linspace(-1,1,50), 'y_pts',linspace(-2,2,100));
0268    img.show_slices.axes_msm = true;
0269    img.show_slices.contour_properties = {'LineWidth',2};
0270    img.show_slices.contour_levels = 1:300;
0271    sp=sp+1;subplot(4,5,sp); show_slices(img) 
0272

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