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

Generated on Sun 29-Dec-2024 11:41:59 by m2html © 2005