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.m 6170 2021-11-05 13:40:53Z bgrychtol $
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 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          % concatenate img.elem_data for each img
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 % TESTS:
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    % EXPECTED FAIL
0079    % imgk(2).elem_data = imgk(2).elem_data';
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    % TODO: This fails because we need a loop in the test function.
0089    %   Lookup whether this can be vectorized in matlab
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);

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