MK_IMAGE: create eidors image object img= mk_image(mdl, elem_data, name) Utility function to create an eidors_image object: Usage 1: img = mk_image( inv_model ) -> uses jacobian backgnd for conductivity Usage 2: mdl can be a fwd_model or inv_model img = mk_image( mdl, 1 ) -> uniform image with conductivity 1 img = mk_image( mdl, 2*ones(n_elems,1) ) -> uniform with c=2 img = mk_image( mdl, 1, 'This name') -> Specify a 'name' attribute Usage 3: create image from previous image, override conductity img = mk_image( other_image, 2 ) -> image with c=2
0001 function img= mk_image(mdl, elem_data, name) 0002 % MK_IMAGE: create eidors image object 0003 % img= mk_image(mdl, elem_data, name) 0004 % 0005 % Utility function to create an eidors_image object: 0006 % Usage 1: 0007 % img = mk_image( inv_model ) -> uses jacobian backgnd for conductivity 0008 % 0009 % Usage 2: mdl can be a fwd_model or inv_model 0010 % img = mk_image( mdl, 1 ) -> uniform image with conductivity 1 0011 % img = mk_image( mdl, 2*ones(n_elems,1) ) -> uniform with c=2 0012 % img = mk_image( mdl, 1, 'This name') -> Specify a 'name' attribute 0013 % 0014 % Usage 3: create image from previous image, override conductity 0015 % img = mk_image( other_image, 2 ) -> image with c=2 0016 0017 % (C) 2008-10 Andy Adler. Licenced under GPL version 2 or 3 0018 % $Id: mk_image.html 2819 2011-09-07 16:43:11Z aadler $ 0019 0020 if isstr(mdl) && strcmp(mdl,'UNIT_TEST'); do_unit_test; return; end 0021 0022 if nargin<3; name = 'Created by mk_image'; end 0023 if nargin<2; 0024 try 0025 elem_data = mdl.jacobian_bkgnd.value; 0026 catch 0027 error('mk_image: for one parameter, needs a mdl.jacobian_bkgnd field'); 0028 end 0029 end 0030 0031 switch mdl.type 0032 case 'inv_model'; mdl = mdl.fwd_model; 0033 case 'fwd_model'; mdl = mdl; % keep model 0034 case 'image'; mdl = mdl.fwd_model; 0035 otherwise; error('mk_image: no inv_model, fwd_model or image object'); 0036 end 0037 0038 img = eidors_obj('image',name); 0039 img.fwd_model = mdl; 0040 img.elem_data = NaN*ones(size(mdl.elems,1),1); 0041 img.elem_data(:) = elem_data; 0042 0043 % TESTS: 0044 function do_unit_test 0045 imdl = mk_common_model('a2c2',8); 0046 im0 = mk_image( imdl ); 0047 unit_test_cmp('im1',im0.elem_data, ones(64,1) ); 0048 0049 im0 = mk_image( imdl, 2 ); 0050 unit_test_cmp('im2',im0.elem_data, 2*ones(64,1) ); 0051 0052 im0 = mk_image( imdl.fwd_model, 3*ones(64,1) ); 0053 unit_test_cmp('im3',im0.elem_data, 3*ones(64,1) );