File size: 2,095 Bytes
c4bb28a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
% Load and render the 10 scans provided with the MM

clear
close all

[model msz] = load_model();

% Load an example scan
fns = dir(fullfile( '..', '02_scans_matlab', '*.mat' ));
for i=1:length(fns)
  fprintf('Loading %s ...\n', fns(i).name);
  load(fullfile( '..', '02_scans_matlab', fns(i).name ));

  % Render it
  rp     = defrp;
  rp.phi = 0.5;
  rp.dir_light.dir = [0;1;1];
  rp.dir_light.intens = 0.6*ones(3,1);
  rp.sbufsize=2000;
  h=figure(1);
  display_face(shape,tex,model.tl,rp);
  set(h, 'name', 'Rendering of the scan');

  % Projection and reconstruction to/from the Morphable Model
  alpha     = object2coef( shape(:), model.shapeMU, model.shapePC, model.shapeEV );
  beta      = object2coef( tex(:),   model.texMU,   model.texPC,   model.texEV );
  shape_rec = coef2object( alpha,    model.shapeMU, model.shapePC, model.shapeEV );
  tex_rec   = coef2object( beta,     model.texMU,   model.texPC,   model.texEV );

  h=figure(2);
  display_face(shape_rec,tex_rec,model.tl,rp);
  set(h, 'name', 'Reconstruction of the 3D Scan from the Morphable Model');
  fprintf('Shape   reconstruction error : %g\n', norm(shape(:)-shape_rec(:)))
  fprintf('Texture reconstruction error : %g\n', norm(tex(:)-tex_rec(:)))

  % Projection and reconstruction to/from the Segmented Morphable Model
  alpha_seg = object2coef( shape(:),  model.shapeMU, model.shapePC, model.shapeEV, model.segbin );
  beta_seg  = object2coef( tex(:),    model.texMU,   model.texPC,   model.texEV,   model.segbin );
  shape_seg = coef2object( alpha_seg, model.shapeMU, model.shapePC, model.shapeEV, model.segMM, model.segMB );
  tex_seg   = coef2object( beta_seg,  model.texMU,   model.texPC,   model.texEV,   model.segMM, model.segMB );
  h=figure(3);
  display_face(shape_seg,tex_seg,model.tl,rp);
  set(h, 'name', 'Reconstruction of the 3D Scan from the Segmented Morphable Model');
  fprintf('Shape   reconstruction error from segmented model : %g\n', norm(shape(:)-shape_seg(:)))
  fprintf('Texture reconstruction error from segmented model : %g\n', norm(tex(:)-tex_seg(:)))

  fprintf('Hit return');
  pause
end