get_img_data

PURPOSE ^

GET_IMG_DATA: get parameter data from eidors image object

SYNOPSIS ^

function [img_data, n_images]= get_img_data(img)

DESCRIPTION ^

 GET_IMG_DATA: get parameter data from eidors image object
 [img_data, n_images]= get_img_data(img)
 img_data - img parameter data mapped onto chosen mesh
   get_img_data looks at the elem_data or node_data
   parameters in the image. If a course2fine parameter
   exists in img.fwd_model, then it is used.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [img_data, n_images]= get_img_data(img)
0002 % GET_IMG_DATA: get parameter data from eidors image object
0003 % [img_data, n_images]= get_img_data(img)
0004 % img_data - img parameter data mapped onto chosen mesh
0005 %   get_img_data looks at the elem_data or node_data
0006 %   parameters in the image. If a course2fine parameter
0007 %   exists in img.fwd_model, then it is used.
0008 
0009 % (C) 2008 Andy Adler. License: GPL version 2 or version 3
0010 % $Id: get_img_data.html 2819 2011-09-07 16:43:11Z aadler $
0011 
0012 % TODO
0013 % FLAGS: flag = 0 (default)
0014 %    get data mapped onto elems in the fwd_model
0015 %if nargin==1; flag=0; end
0016 
0017 % TEST
0018 if isstr(img) && strcmp(img,'UNIT_TEST'); do_unit_test; return; end
0019 
0020 if ~strcmp( img(1).type, 'image' );
0021     error('get_img_data expects an image type object');
0022     return;
0023 end
0024 
0025 try
0026    img_data= [img.elem_data];
0027 catch
0028    img_data= [img.node_data];
0029 end
0030 
0031 if size(img_data,1)==1; img_data=img_data';end
0032 
0033 n_images= size(img_data,2);
0034 
0035 try
0036    c2f= img.fwd_model.coarse2fine;
0037 catch
0038    return;
0039 end
0040 
0041 if size(img_data,1)==size(c2f,2)
0042    img_data=c2f * img_data;
0043 end
0044 
0045 % TESTS:
0046 function do_unit_test
0047    img=calc_jacobian_bkgnd(mk_common_model('a2c0',8)); 
0048    unit_test_cmp('elem_01', get_img_data(img), ones(64,1) )
0049 
0050    imgk = img; imgk.elem_data = img.elem_data';
0051    unit_test_cmp('elem_02', get_img_data(imgk), ones(64,1) )
0052 
0053    imgk = img; imgk(2) = img;
0054    unit_test_cmp('elem_03', get_img_data(imgk), ones(64,2) )
0055 
0056    % EXPECTED FAIL
0057    % imgk(2).elem_data = imgk(2).elem_data';
0058 
0059    imgk(1).elem_data = imgk(1).elem_data*[1,2];
0060    unit_test_cmp('elem_04', get_img_data(imgk(1)), ones(64,1)*[1,2] )
0061    unit_test_cmp('elem_05', get_img_data(imgk), ones(64,1)*[1,2,1] )
0062 
0063    nd =ones(size(img.fwd_model.nodes,1),1);
0064    imgn = rmfield(img,'elem_data'); imgn.node_data=nd;
0065    unit_test_cmp('node_01', get_img_data(imgn), nd)
0066 
0067    i2 = mk_common_model('b2c0',8); fmdl2= i2.fwd_model;
0068    c2f = mk_coarse_fine_mapping(fmdl2, img.fwd_model);
0069    img.fwd_model.coarse2fine = c2f;
0070    unit_test_cmp('c2f_01', get_img_data(img), c2f*ones(64,1))
0071     
0072    % TODO ADD TESTS WHICH GIVE C2F ON NODE_DATA

Generated on Tue 09-Aug-2011 11:38:31 by m2html © 2005