rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
init_values_grey_image.m
1 function U0 = init_values_grey_image(glob,params)
2 %function U0 = init_values_grey_image(glob,params)
3 %
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
9 %
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
22 %
23 % in 'coefficient' mode the params structure is empty
24 
25 % glob column check
26 if params.debug
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');
29  if params.debug > 2
30  keyboard;
31  end
32  end
33 end
34 if nargin ~= 2
35  error('wrong number of parameters!');
36 end;
37 decomp_mode = params.decomp_mode;
38 
39 
40 
41 
42 
43 
44 ncomp = 1+length(params.c_init_xdivisions);
45 if decomp_mode ~= 2
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);
51  XI = max(XI,0);
52  XI = min(XI,size(img,2));
53  XI = ceil(XI);
54  fi = find(XI==0);
55  if ~isempty(fi)
56  XI(fi)= 1;
57  end;
58  YI = (glob(:,2)-params.c_init_ymin)/(params.c_init_ymax- ...
59  params.c_init_ymin)* size(img,1);
60  YI = max(YI,0);
61  YI = min(YI,size(img,1));
62  % reflect y coordinate
63  YI = size(img,1)-YI;
64  YI = ceil(YI);
65  fi = find(YI==0);
66  if ~isempty(fi)
67  YI(fi)= 1;
68  end;
69 
70  ind = sub2ind(size(img),YI,XI);
71  I = img(ind);
72 
73  U0comp = cell(ncomp,1);
74  xdivs = [0;params.c_init_xdivisions(:);params.c_init_xmax];
75  for i = 1:ncomp
76  U0 = zeros(length(glob(:,1)),1);
77  fi = find( (glob(:,1)<xdivs(i+1)) & (glob(:,1)>=xdivs(i)));
78  if ~isempty(fi)
79  U0(fi) = I(fi);
80  end;
81  U0comp{i} = U0;
82  end;
83 end;
84 
85 % determine coefficients:
86 coeff = zeros(ncomp,1);
87 coeff = (0:(ncomp-1))/ncomp;
88 coeff = (params.c_init - coeff)*ncomp;
89 coeff = min(coeff,1);
90 coeff = max(coeff,0);
91 
92 % now return the correct quantity
93 if decomp_mode == 2
94  U0 = coeff;
95 elseif decomp_mode == 0
96  U0 = lincomb_sequence(U0comp,coeff);
97 elseif decomp_mode == 1
98  U0 = U0comp;
99 else
100  error(['decomp_mode number ', params.decomp_mode, ' is unknown.']);
101 end;
102 respected_decomp_mode = 1;
103