1 function U0 = init_values_grey_image(glob,params)
2 %
function U0 = init_values_grey_image(glob,params)
4 %
function constructing the initial values of the convection diffusion
5 % problem in the specified global points glob and parameters.
6 % load grey value image as initial data,
7 % a grey value image is loaded mapping 0 to 0 and 255 to c_init
8 % with bilinear interpolation
10 % required fields in params:
11 % c_init : parameter weighting the components
12 % c_init_filename : name of image file
13 % c_init_xmin : image is mapped to specified rectangle
14 % c_init_xmax : image is mapped to specified rectangle
15 % c_init_ymin : image is mapped to specified rectangle
16 % c_init_ymax : image is mapped to specified rectangle
17 % c_init_xdivisions : vector of divisions, i.e intervals,
18 % e.g. borders of letters in an image
19 % determines number of components. c_init = 0
20 % => full weight to leftmost part of image
21 % c_init = 1 => full weight to complete image
23 % in
'coefficient' mode the params structure is empty
27 if ~isempty(glob) && size(glob,1) < size(glob,2)
28 warning('coordinates in variable glob are given row-wise, but expected them to be column-wise');
35 error('wrong number of parameters!');
37 decomp_mode = params.decomp_mode;
44 ncomp = 1+length(params.c_init_xdivisions);
46 % determine components and perform linear combination
47 img =
double(imread(params.c_init_filename))/255;
48 %erstmal ohne bilineare Interpolation:
49 XI = (glob(:,1)-params.c_init_xmin)/(params.c_init_xmax- ...
50 params.c_init_xmin)* size(img,2);
52 XI = min(XI,size(img,2));
58 YI = (glob(:,2)-params.c_init_ymin)/(params.c_init_ymax- ...
59 params.c_init_ymin)* size(img,1);
61 YI = min(YI,size(img,1));
62 % reflect y coordinate
70 ind = sub2ind(size(img),YI,XI);
73 U0comp = cell(ncomp,1);
74 xdivs = [0;params.c_init_xdivisions(:);params.c_init_xmax];
76 U0 = zeros(length(glob(:,1)),1);
77 fi = find( (glob(:,1)<xdivs(i+1)) & (glob(:,1)>=xdivs(i)));
85 % determine coefficients:
86 coeff = zeros(ncomp,1);
87 coeff = (0:(ncomp-1))/ncomp;
88 coeff = (params.c_init - coeff)*ncomp;
92 % now
return the correct quantity
95 elseif decomp_mode == 0
96 U0 = lincomb_sequence(U0comp,coeff);
97 elseif decomp_mode == 1
100 error([
'decomp_mode number ', params.decomp_mode,
' is unknown.']);
102 respected_decomp_mode = 1;