solve_RM_2Dslice

PURPOSE ^

SOLVE_RM_2DSLICE: cut slices out of a 3D model

SYNOPSIS ^

function imdl = solve_RM_2Dslice(imdl, sel_fcn)

DESCRIPTION ^

 SOLVE_RM_2DSLICE: cut slices out of a 3D model
  which has reconstruction matrix calculated

 Basic usage
 For example, given a 3D GREIT model
    vopt.zvec= 0.5:0.2:2.5;
    vopt.imgsz = [32 32];
    [imdl,opt.distr] = GREIT3D_distribution(fmdl, vopt);
    imdl = mk_GREIT_model(imdl, 0.20, [], opt);

 One could cut the z=1 slice as
    imdl2= solve_RM_2Dslice(imdl, 1.0);
 Or using 
    sel_fcn = inline('abs(z-1.0)<0.2'); OR
    sel_fcn = 'abs(z-1.0)<0.2 | abs(z-2.0)<0.2' ; % two planes
    imdl2= solve_RM_2Dslice(imdl, sel_fcn);
 
 Note that the reconstruction planes are between the
 cut planes specified in vopt.zvec

 options:
  imdl.solve_RM_2Dslice.vert_tol = .001;
       % Vertical tolerance for elems on plane (Default .001)
  imdl.solve_RM_2Dslice.keep3D = 1; %keep 3D aspect of cuts

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function imdl = solve_RM_2Dslice(imdl, sel_fcn)
0002 % SOLVE_RM_2DSLICE: cut slices out of a 3D model
0003 %  which has reconstruction matrix calculated
0004 %
0005 % Basic usage
0006 % For example, given a 3D GREIT model
0007 %    vopt.zvec= 0.5:0.2:2.5;
0008 %    vopt.imgsz = [32 32];
0009 %    [imdl,opt.distr] = GREIT3D_distribution(fmdl, vopt);
0010 %    imdl = mk_GREIT_model(imdl, 0.20, [], opt);
0011 %
0012 % One could cut the z=1 slice as
0013 %    imdl2= solve_RM_2Dslice(imdl, 1.0);
0014 % Or using
0015 %    sel_fcn = inline('abs(z-1.0)<0.2'); OR
0016 %    sel_fcn = 'abs(z-1.0)<0.2 | abs(z-2.0)<0.2' ; % two planes
0017 %    imdl2= solve_RM_2Dslice(imdl, sel_fcn);
0018 %
0019 % Note that the reconstruction planes are between the
0020 % cut planes specified in vopt.zvec
0021 %
0022 % options:
0023 %  imdl.solve_RM_2Dslice.vert_tol = .001;
0024 %       % Vertical tolerance for elems on plane (Default .001)
0025 %  imdl.solve_RM_2Dslice.keep3D = 1; %keep 3D aspect of cuts
0026 
0027 % (C) 2015-2018 Andy Adler and Bartlomiej Grychtol
0028 % License: GPL version 2 or version 3
0029 % $Id: solve_RM_2Dslice.m 6366 2022-05-05 13:53:25Z aadler $
0030 
0031 if ischar(imdl) && strcmp(imdl,'UNIT_TEST'); do_unit_test; return; end
0032 
0033 % Options
0034 vert_tol = .001; try
0035   vert_tol = imdl.solve_RM_2Dslice.vert_tol;
0036 end
0037 
0038 keep3D=0; try
0039   keep3D = imdl.solve_RM_2Dslice.keep3D;
0040 end
0041 
0042 ctr = interp_mesh(imdl.rec_model); ct3= ctr(:,3);
0043 
0044 if isnumeric( sel_fcn )
0045    ff = abs(ct3-sel_fcn) < vert_tol;
0046 else
0047     if ischar(sel_fcn) %  we have a string, create a function
0048       sel_fcn = inline(sel_fcn, 'z');
0049     end
0050     ff = feval(sel_fcn,ct3);
0051 end
0052 imdl.rec_model.coarse2fine(~ff,:) = [];
0053 imdl.rec_model.elems(~ff,:) = [];
0054 
0055 fb = any(imdl.rec_model.coarse2fine,1);
0056 imdl.rec_model.coarse2fine(:,~fb) = [];
0057 imdl.fwd_model.coarse2fine(:,~fb) = [];
0058 imdl.solve_use_matrix.RM(~fb,:) = [];
0059 if isfield(imdl.solve_use_matrix,'PJt')
0060    imdl.solve_use_matrix.PJt(~fb,:) = [];
0061 end
0062 
0063 if keep3D; 
0064    imdl.rec_model.boundary = find_boundary(imdl.rec_model);
0065    return;
0066 end
0067 
0068 imdl.rec_model.nodes(:,3) = [];
0069 imdl.rec_model.elems(:,4) = [];
0070 
0071 nelems = imdl.rec_model.elems;
0072 nnodes = unique(nelems(:));
0073 nnidx = zeros(max(nnodes),1);
0074 nnidx(nnodes) = 1:length(nnodes);
0075 nnodes = imdl.rec_model.nodes(nnodes,:);
0076 nelems = reshape(nnidx(nelems),size(nelems));
0077 imdl.rec_model.nodes = nnodes;
0078 imdl.rec_model.elems = nelems;
0079 imdl.rec_model.boundary = find_boundary(imdl.rec_model);
0080 
0081 function do_unit_test
0082    [vh,vi] = test_fwd_solutions;
0083    % inverse geometry
0084    fmdl= ng_mk_cyl_models([4,1,.5],[16,1.5,2.5],[0.05]);
0085    fmdl= mystim_square(fmdl);
0086 
0087    vopt.imgsz = [32 32];
0088    vopt.zvec = linspace( 0.75,3.25,6);
0089    vopt.save_memory = 1;
0090 %  opt.noise_figure = 2;
0091    weight = 8.42412109211;
0092    [imdl,opt.distr] = GREIT3D_distribution(fmdl, vopt);
0093    imdl = mk_GREIT_model(imdl, 0.2, weight, opt);
0094 
0095    unit_test_cmp('RM size', size(imdl.solve_use_matrix.RM), [4280,928]);
0096    unit_test_cmp('RM', imdl.solve_use_matrix.RM(1,1:2), ...
0097        [7.896475314622105 -3.130412179150207], 1e-8);
0098 
0099 
0100 
0101    img = inv_solve(imdl, vh, vi);
0102    unit_test_cmp('img size', size(img.elem_data), [4280,5]);
0103    [mm,ll] =max(img.elem_data(:,1));
0104    unit_test_cmp('img', [mm,ll], ...
0105        [0.426631207850641, 1274], 1e-10);
0106 
0107    img.show_slices.img_cols = 1;
0108    slice1 = calc_slices(img);
0109    subplot(231); show_fem(fmdl); title 'fmdl'
0110    subplot(234); show_fem(img);  title '3D'
0111    subplot(232); show_slices(img,[inf,inf,2]); title '3D slice';
0112    imd2 = solve_RM_2Dslice(imdl, 2.0);
0113 
0114    unit_test_cmp('RM size', size(imd2.solve_use_matrix.RM), [856,928]);
0115    unit_test_cmp('RM', imd2.solve_use_matrix.RM(1,1:2), ...
0116        [-13.546930204198315   9.664897892799864], 1e-8);
0117 
0118    img = inv_solve(imd2, vh, vi);
0119    unit_test_cmp('img size', size(img.elem_data), [856,5]);
0120    [mm,ll] =max(img.elem_data(:,1));
0121    unit_test_cmp('img', [mm,ll], ...
0122        [0.031608449353163, 453], 1e-10);
0123    slice2 = calc_slices(img);
0124 
0125    unit_test_cmp('slice Nan', isnan(slice1), isnan(slice2))
0126    slice1(isnan(slice1))= 0;
0127    slice2(isnan(slice2))= 0;
0128    unit_test_cmp('slice value', slice1, slice2, 1e-10)
0129 
0130    
0131    imdl.solve_RM_2Dslice.keep3D = 1;
0132    imd3 = solve_RM_2Dslice(imdl, 1.0);
0133    img = inv_solve(imd3, vh, vi);
0134    subplot(235); show_fem(img);
0135    
0136    sel_fcn = inline('abs(z-1.0)<0.2','z');
0137    imd3 = solve_RM_2Dslice(imdl, sel_fcn);
0138 
0139    sel_fcn = 'abs(z-1.0)<0.2 | abs(z-2.0)<0.2' ;
0140    imd3 = solve_RM_2Dslice(imdl, sel_fcn);
0141    img = inv_solve(imd3, vh, vi);
0142    subplot(236); show_fem(img);
0143 
0144 function fmdl = mystim_square(fmdl);
0145    [~,fmdl] = elec_rearrange([16,2],'square', fmdl);
0146    [fmdl.stimulation, fmdl.meas_select] =  ...
0147        mk_stim_patterns(32,1,[0,5],[0,5],{},1);
0148 
0149 function [vh,vi] = test_fwd_solutions;
0150    posns= linspace(1.0,3.0,5);
0151    str=''; for i=1:length(posns);
0152       extra{i} = sprintf('ball%03d',round(posns(i)*100));
0153       str = [str,sprintf('solid %s=sphere(0.5,0,%f;0.1); ', extra{i}, posns(i))];
0154    end
0155    extra{i+1} = str;
0156    fmdl= ng_mk_cyl_models([4,1,.2],[16,1.5,2.5],[0.05],extra); 
0157    fmdl = mystim_square(fmdl);
0158    
0159    img= mk_image(fmdl,1);
0160    vh = fwd_solve(img);
0161    %vh = add_noise(2000, vh);
0162    for i=1:length(posns);
0163       img= mk_image(fmdl,1);
0164       img.elem_data(fmdl.mat_idx{i+1}) = 2;
0165       vi{i} = fwd_solve(img);
0166    end;
0167    vi = [vi{:}];

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