0001 function [inhomg_img, demo_img] = demo_real;
0002
0003
0004
0005
0006
0007
0008 eidors_msg('log_level',2);
0009
0010 disp('step 1: create FEM model structure');
0011
0012
0013
0014
0015 [vtx,simp, bdy] = get_model_elems;
0016
0017 demo_mdl.name = 'demo real model';
0018 demo_mdl.nodes= vtx;
0019 demo_mdl.elems= simp;
0020 demo_mdl.boundary= bdy;
0021 demo_mdl.solve= 'np_fwd_solve';
0022 demo_mdl.jacobian= 'np_calc_jacobian';
0023 demo_mdl.system_mat= 'np_calc_system_mat';
0024
0025 disp('step 2: create FEM model electrodes definitions');
0026
0027 [gnd_ind, electrodes, perm_sym, elec, protocol, no_pl] = get_model_elecs;
0028 demo_mdl.gnd_node= gnd_ind;
0029 demo_mdl.electrode = electrodes;
0030 demo_mdl.np_fwd_solve.perm_sym = perm_sym;
0031
0032 disp('step 3: create FEM model stimulation and measurement patterns');
0033
0034 [stimulations ] = get_model_stim( demo_mdl );
0035 demo_mdl.stimulation= stimulations;
0036
0037 demo_mdl= eidors_obj('fwd_model', demo_mdl);
0038
0039 disp('step 4: simulate data for homogeneous medium');
0040
0041
0042
0043
0044
0045 mat= ones( size(demo_mdl.elems,1) ,1);
0046
0047 homg_img= eidors_obj('image', 'homogeneous image', ...
0048 'elem_data', mat, ...
0049 'fwd_model', demo_mdl );
0050
0051 homg_data=fwd_solve( demo_mdl, homg_img);
0052
0053 disp('step 5: simulate data for inhomogeneous medium');
0054
0055
0056
0057
0058 load( 'datacom.mat' ,'A','B')
0059 mat(A)= mat(A)+0.15;
0060 mat(B)= mat(B)-0.20;
0061
0062 inhomg_img= eidors_obj('image', 'inhomogeneous image', ...
0063 'elem_data', mat, ...
0064 'fwd_model', demo_mdl );
0065
0066 show_fem( inhomg_img );
0067
0068 inhomg_data=fwd_solve( demo_mdl, inhomg_img);
0069
0070 disp('step 6: add noise to simulated data');
0071
0072 inhomg_data.meas = inhomg_data.meas + 1e-5*randn(size(inhomg_data.meas));
0073 homg_data.meas = homg_data.meas + 1e-5*randn(size( homg_data.meas));
0074
0075 disp('step 7: create inverse model');
0076
0077
0078 demo_inv.name= 'Nick Polydorides EIT inverse';
0079 demo_inv.solve= 'np_inv_solve';
0080 demo_inv.hyperparameter.value = 1e-3;
0081 demo_inv.R_prior= 'np_calc_image_prior';
0082 demo_inv.np_calc_image_prior.parameters= [3 1];
0083 demo_inv.jacobian_bkgnd.value= 1;
0084 demo_inv.reconst_type= 'difference';
0085 demo_inv.fwd_model= demo_mdl;
0086 demo_inv= eidors_obj('inv_model', demo_inv);
0087
0088 disp('step 8: solve inverse model');
0089
0090 demo_img= inv_solve( demo_inv, homg_data, inhomg_data);
0091
0092 disp('step 9: display results');
0093
0094 levels=[ 2.63 2.10 1.72 1.10 0.83 0.10 ];
0095
0096 figure; image_levels( inhomg_img, levels );
0097
0098 demo_img.name= 'Reconstructed conductivity distribution';
0099 demo_img.calc_colours.ref_level = 0;
0100 figure; image_levels( demo_img, levels );
0101
0102 function [vtx,simp,bdy] = get_model_elems;
0103
0104
0105
0106 load('datareal.mat','vtx','simp');
0107 bdy= find_boundary( simp );
0108
0109
0110
0111 function [gnd_ind, electrodes, perm_sym, elec, protocol, no_pl] = get_model_elecs;
0112
0113
0114
0115
0116
0117
0118
0119 load('datareal.mat','gnd_ind','elec','zc','protocol','no_pl');
0120
0121 for i=1:length(zc)
0122 electrodes(i).z_contact= zc(i);
0123 electrodes(i).nodes= unique( elec(i,:) );
0124 end
0125
0126 perm_sym='{n}';
0127
0128
0129 function [stimulations] = get_model_stim( mdl );
0130
0131 load('datareal.mat','protocol','no_pl','elec');
0132 [I,Ib] = set_3d_currents(protocol, ...
0133 elec, ...
0134 mdl.nodes, ...
0135 mdl.gnd_node, ...
0136 no_pl);
0137
0138
0139
0140
0141 [jnk,jnk,indH,indV,jnk] = get_3d_meas( ...
0142 elec, mdl.nodes, ...
0143 zeros(size(I)), ...
0144 Ib, no_pl );
0145 n_elec= size(elec,1);
0146 n_meas= size(indH,1) / size(Ib,2);
0147 for i=1:size(Ib,2)
0148 stimulations(i).stimulation= 'Amp';
0149 stimulations(i).stim_pattern= Ib(:,i);
0150 idx= ( 1+ (i-1)*n_meas ):( i*n_meas );
0151 meas_pat = sparse( (1:n_meas)'*[1,1], ...
0152 indH( idx, : ), ...
0153 ones(n_meas,2)*[1,0;0,-1], ...
0154 n_meas, n_elec );
0155 stimulations(i).meas_pattern= meas_pat;
0156 end
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168