0001 function [img_data, n_images]= get_img_data(img)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 if ischar(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 if ~isfield(img,'elem_data') && ~isfield(img,'node_data')
0026 img = data_mapper(img);
0027 end
0028
0029 if isfield(img(1),'elem_data')
0030 for i=1:length(img(:))
0031 try
0032 img_data{i}= [img(i).elem_data(:,img(i).get_img_data.frame_select)];
0033 catch
0034
0035 img_data{i}= [img(i).elem_data];
0036 end
0037 end
0038 img_data = [img_data{:}];
0039 elseif isfield(img,'node_data')
0040 for i=1:length(img(:))
0041 try
0042 img_data{i}= [img(i).node_data(:,img(i).get_img_data.frame_select)];
0043 catch
0044 img_data{i}= [img(i).node_data];
0045 end
0046 end
0047 img_data = [img_data{:}];
0048 else
0049 error('No field elem_data or node_data found on img');
0050 end
0051
0052 if size(img_data,1)==1; img_data=img_data';end
0053
0054 n_images= size(img_data,2);
0055
0056 try
0057 c2f= img.fwd_model.coarse2fine;
0058 catch
0059 return;
0060 end
0061
0062 if size(img_data,1)==size(c2f,2)
0063 img_data=c2f * img_data;
0064 end
0065
0066
0067 function do_unit_test
0068 img=calc_jacobian_bkgnd(mk_common_model('a2c0',8));
0069 unit_test_cmp('elem_01', get_img_data(img), ones(64,1) )
0070
0071 imgk = img; imgk.elem_data = img.elem_data';
0072 unit_test_cmp('elem_02', get_img_data(imgk), ones(64,1) )
0073
0074
0075 imgk = img; imgk(2) = img;
0076 unit_test_cmp('elem_03', get_img_data(imgk), ones(64,2) )
0077
0078
0079
0080
0081 imgk(1).elem_data = imgk(1).elem_data*[1,2];
0082 unit_test_cmp('elem_04', get_img_data(imgk(1)), ones(64,1)*[1,2] )
0083 unit_test_cmp('elem_05', get_img_data(imgk), ones(64,1)*[1,2,1] )
0084
0085 imgk = img; imgk.elem_data = img.elem_data*[1,2];
0086 imgk.get_img_data.frame_select = 2;
0087 unit_test_cmp('elem_06', get_img_data(imgk), 2*ones(64,1) )
0088
0089
0090
0091 imgk(2) = imgk(1); imgk(2).elem_data = img.elem_data*[3,4];
0092 imgk(2).get_img_data.frame_select = 2;
0093 unit_test_cmp('elem_07', get_img_data(imgk), ones(64,1)*[2,4] )
0094 imgk(2).get_img_data.frame_select = 1:2;
0095 unit_test_cmp('elem_08', get_img_data(imgk), ones(64,1)*[2,3,4] )
0096
0097 nd =ones(num_nodes(img),1);
0098 imgn = rmfield(img,'elem_data'); imgn.node_data=nd;
0099 unit_test_cmp('node_01', get_img_data(imgn), nd)
0100
0101 imgn.node_data = nd*[3,4,5];
0102 unit_test_cmp('node_02', get_img_data(imgn), nd*[3,4,5]);
0103 imgn(2) = imgn;
0104 unit_test_cmp('node_03', get_img_data(imgn), nd*[3,4,5,3,4,5]);
0105 imgn(1).get_img_data.frame_select = 1;
0106 unit_test_cmp('node_04', get_img_data(imgn), nd*[3,3,4,5]);
0107 imgn(2).get_img_data.frame_select = 3;
0108 unit_test_cmp('node_05', get_img_data(imgn), nd*[3,5]);
0109
0110
0111 i2 = mk_common_model('b2c0',8); fmdl2= i2.fwd_model;
0112 c2f = mk_coarse_fine_mapping(fmdl2, img.fwd_model);