mk_image

PURPOSE ^

MK_IMAGE: create eidors image object

SYNOPSIS ^

function img= mk_image(mdl, elem_data, params, name)

DESCRIPTION ^

 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, 2*ones(n_nodes,1) ) -> image with node data
   img = mk_image( mdl, 1, 'This name') -> Specify a 'name' attribute
   img = mk_image( mdl, ones(n_elems,3) );

 Usage 3: create image from previous image, override conductity
  img = mk_image( other_image, 2 ) -> image with c=2

 Usage 4: create image with specific 'params' properties
  img = mk_image( mdl, 3*ones(64,1),'resistivity' ); % resistivity image

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function img= mk_image(mdl, elem_data, params, 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, 2*ones(n_nodes,1) ) -> image with node data
0013 %   img = mk_image( mdl, 1, 'This name') -> Specify a 'name' attribute
0014 %   img = mk_image( mdl, ones(n_elems,3) );
0015 %
0016 % Usage 3: create image from previous image, override conductity
0017 %  img = mk_image( other_image, 2 ) -> image with c=2
0018 %
0019 % Usage 4: create image with specific 'params' properties
0020 %  img = mk_image( mdl, 3*ones(64,1),'resistivity' ); % resistivity image
0021 
0022 % (C) 2008-12 Andy Adler and Bartlomiej Grychtol.
0023 % Licenced under GPL version 2 or 3
0024 % $Id: mk_image.m 6161 2021-11-02 14:44:49Z bgrychtol $
0025 
0026 if ischar(mdl) && strcmp(mdl,'UNIT_TEST'); do_unit_test; return; end
0027 
0028 default_params = no_params; % later: conductivity ?
0029 default_name    = 'Created by mk_image';
0030 if nargin<3
0031     name = default_name;
0032     params = default_params;
0033 elseif nargin < 4 % preserve old interface
0034     if ismember(params,supported_params)
0035         name = default_name;
0036     else
0037         name = params;
0038         params = default_params;
0039     end
0040 end
0041 
0042 % if nargin<2;
0043 %    try
0044 %      elem_data = mdl.jacobian_bkgnd.value;
0045 %    catch
0046 %      error('mk_image: for one parameter, needs a mdl.jacobian_bkgnd field');
0047 %    end
0048 % end
0049 
0050 switch mdl.type
0051    case 'inv_model'
0052       if nargin == 1
0053          img = calc_jacobian_bkgnd(mdl);
0054          return
0055       else
0056          mdl = mdl.fwd_model;
0057          % warning('Ignoring inv_model.jacobian_bkgnd in favour of the supplied elem_data');
0058       end
0059    case 'fwd_model'
0060       mdl = mdl; % keep model
0061    case 'image'
0062       if nargin == 1
0063          img = data_mapper(mdl);
0064          return
0065       end
0066       mdl = mdl.fwd_model;
0067    otherwise; error('mk_image: no inv_model, fwd_model or image object');
0068 end
0069 
0070 img = eidors_obj('image',name);
0071 img.fwd_model = mdl;
0072 if isfield(mdl,'show_slices');
0073     img.show_slices = mdl.show_slices;
0074 end
0075 img = fill_in_data(img,elem_data,params);
0076 % img.current_params = params;
0077 
0078 function str = no_params
0079 str = 'unspecified';
0080 
0081 function img = fill_in_data(img,elem_data,params)
0082   % If image is presented as row vector, then transpose
0083   %  Shouldn't happen, but for matlab bugs
0084   if size(elem_data,1) == 1 && ...
0085      size(elem_data,2) >  1 
0086      elem_data = elem_data.';
0087   end
0088   switch size(elem_data,1)
0089      case 1
0090         sz = size(img.fwd_model.elems,1);
0091         elem_data_mat =    NaN*ones(sz,1);
0092         elem_data_mat(:) = elem_data;
0093         if strcmp(params,no_params);
0094             img.elem_data = elem_data_mat;
0095         else
0096             img.(params).elem_data = elem_data_mat;
0097         end
0098 
0099      case num_elems( img )
0100         if strcmp(params,no_params);
0101             img.elem_data = elem_data;
0102         else
0103             img.(params).elem_data = elem_data;
0104         end
0105           
0106       case num_nodes( img )
0107         if strcmp(params,no_params);
0108             img.node_data = elem_data;
0109         else
0110             img.(params).node_data = elem_data;
0111         end
0112         
0113       case size(img.fwd_model.coarse2fine,2)
0114         if strcmp(params,no_params);
0115             img.elem_data = elem_data;
0116         else
0117             img.(params).elem_data = elem_data;
0118         end
0119 
0120      otherwise
0121         error('Don''t understand number of elements.');
0122   end
0123 
0124 % TESTS:
0125 function do_unit_test
0126    imdl = mk_common_model('a2c2',8);
0127    im0 = mk_image( imdl );
0128    unit_test_cmp('im1',im0.elem_data, ones(64,1) );
0129 
0130    im0 = mk_image( imdl, 2 ); % warning
0131    unit_test_cmp('im2',im0.elem_data, 2*ones(64,1) );
0132 
0133    im0 = mk_image( imdl.fwd_model, 3*ones(64,1) );
0134    unit_test_cmp('im3',im0.elem_data, 3*ones(64,1) );
0135 
0136    im0 = mk_image(im0); % no change
0137    unit_test_cmp('im4',im0.elem_data, 3*ones(64,1) );
0138 
0139    im0.conductivity.elem_data = im0.elem_data;
0140    im0 = rmfield(im0, 'elem_data');
0141    im1 = mk_image(im0); % use data_mapper
0142    unit_test_cmp('im5',im1.elem_data, 3*ones(64,1) );
0143 
0144    im0.resistivity.node_data = 5;
0145    im0.data_mapper = 'resistivity';
0146    im1 = mk_image(im0); % use data_mapper
0147    unit_test_cmp('im6',im1.node_data(5), 5 );
0148 
0149    imdl.jacobian_bkgnd = rmfield(imdl.jacobian_bkgnd, 'value');
0150    imdl.jacobian_bkgnd.conductivity = im0.conductivity;
0151    im2 = mk_image(imdl);
0152    unit_test_cmp('im7',im2.conductivity.elem_data, 3*ones(64,1) );
0153 
0154    im0 = mk_image( imdl.fwd_model, 3*ones(64,1),'my_name' );
0155    unit_test_cmp('im8a',im0.elem_data, 3*ones(64,1) );
0156 
0157    im0 = mk_image( imdl.fwd_model, 3*ones(64,1),'resistivity' );
0158    unit_test_cmp('im8b',im0.resistivity.elem_data, 3*ones(64,1) );
0159 
0160    im0 = mk_image( imdl.fwd_model, 2*ones(64,3),'resistivity' );
0161    unit_test_cmp('im8c',im0.resistivity.elem_data, 2*ones(64,3) );
0162 
0163    im0 = mk_image( imdl.fwd_model, 3*ones(64,1),'resistivity','my name' );
0164    unit_test_cmp('im9a',im0.resistivity.elem_data, 3*ones(64,1) );
0165    unit_test_cmp('im9b',im0.name, 'my name' );

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