<?php

echo '<html>';
echo '<link rel="stylesheet" href="style.css" />';
echo '<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
  <META HTTP-EQUIV="Expires" CONTENT="-1">';
echo '<div id="wrap">';

header("Refresh:0");

$query = $_SERVER['QUERY_STRING'];
parse_str($query);

$dirname = "../aligned_data/".$input_set."_kelco";
$images = glob($dirname."/*.jpg");
$counter=0;
$ex_ids=array(1);
$styles=array('kelco', 'martin', 'platon');

$martin_choice=array(
5,3,1,2,1,
1,1,5,1,4,
1,1,2,1,1,
4,1,2,5,2,
1,1,5,1,3,
1,1,1,3,1,
1,1,5,1,1,
1,1,2,3,1,
1,1,1,4,4,
5,4,1,2,2,
2,1,3,2,1,
1,3,4,2,1,
1,2,1,1,4,
3,1,1,4,3,
1,2,4,4,3,
3,1,1,1,4,
1,1,1,2,1,
2,1,1,3,4,
1,2,3,1,2,
1,1,5);

$kelco_choice=array(
1,1,1,1,1,
2,1,1,1,1,
1,1,1,1,1,
1,1,1,1,2,
1,1,1,1,1,
1,1,1,1,2,
1,2,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,4,3,1,1,
1,1,1,2,1,
1,1,1,1,3,
3,1,1,1,1,
1,1,1,1,1,
1,1,3,2,2,
1,3,2,1,1,
3,1,1,1,1,
1,1,1,1,1,
1,1,1);

$platon_choice=array(
1,1,1,1,1,#5
1,2,4,3,1,#10
2,1,1,1,2,#15
1,1,1,2,5,#20
3,5,3,5,3,#25
1,1,1,2,1,#30
1,2,1,1,3,#35
1,1,1,2,1,#40
1,1,1,1,1,#45
2,1,1,1,1,#50
1,2,3,1,1,#55
2,2,1,1,4,#60
1,1,1,2,2,#65
2,1,1,2,3,#70
2,1,1,2,1,#75
1,1,3,1,2,#80
1,2,2,1,2,#85
1,1,1,2,1,#90
1,1,1,1,1,#95
1,1,1,);

$eye_highlight=array(
'156243258_ca4e3c085a_o',
'4583418416_290d7e40a4_o',
'6291840705_57ae5bc5ab_o',
'8863596917_7e2a5d38a1_o',);

$alpha_mask=array(
  '3608529260_8928fe1bd0_o',
  '4583420392_1056f22531_o',
  );

$cmap_platon=array(
  '2328140094_3005a149d4_o',
  '397673947_111f381c41_o',
  '5832044131_cba1862391_o',
  '5832598432_aa382b5080_o',
  '8702724096_48da1a4fe1_o');

# Make the choice in dictionary form 
function cut_fname($in){
  return basename($in, '.jpg');
}

$fnames=array_map("cut_fname", $images);
$martin_choice=array_combine($fnames,$martin_choice);
$kelco_choice=array_combine($fnames,$kelco_choice);
$platon_choice=array_combine($fnames,$platon_choice);


# Organize the order
$to_Top=array(32, 29, 6, 9, 11,  19,47,  8, 16, 76,);
$to_Hide=array(35, 91, 95, 13);
$top_element=array();
$re_order=True;

if ($re_order){
  foreach($to_Hide as $hide){
    unset($images[$hide]);}
  foreach($to_Top as $top){
    array_push($top_element, $images[$top]);
    unset($images[$top]);}
  foreach($top_element as $top){
    array_unshift($images, $top);}

    $images=array_values($images);
}


echo '<font face="arial">';

echo '<h1><div id="title">Additional Results for Paper: <br> Style Transfer for Headshot Portraits <div></h1>';


echo '<h2><b>Description:</b> 
      <br> we run style transfer on '.htmlspecialchars(sizeof($images)).' inputs unbiasedly downloaded from Flickr. 
      Collection workflow is described in the main paper.
      <br> Each row shows an input as well as three style transferred results. We show the examples in the insets. 
      <br> ** For the best view, please make sure all results from the same input stay in the same line.

      <p><b> Workflow:</b>
      <br> for each style, our automatic selection algorithm picks up the top 5 
      candidates for style transfer. 
      <br> Then we show the best result based on the matching quality, selected by us.
      <br> We show the example rank in the caption under the output. Most of them are the first choice. 

      <!---br> For some results, we corect them manually, denoted by the following notations in the caption under the result:
      <li> E*: fix iris location by hand ('.htmlspecialchars(sizeof($eye_highlight)).' inputs).</li>
      <li> A*: fix alpha mask by hand ('.htmlspecialchars(sizeof($alpha_mask)).' inputs).</li>
      <li> C*: use constraint map to fix the mis-matching between input and example ('.sizeof($cmap_platon).' results).</li---!>

  
  </h2>';


echo '<hr>';

$start_num=0;
$end_num=sizeof($images)-1;

if ($page==1){
  $start_num=0;
  $end_num=$start_num+50-1;
}elseif ($page==2){
  $start_num=50;
  $end_num=sizeof($images)-1;}

echo '<h1> <a href=supp.php?input_set=flickr2&flag_select=1&page=1>[Show inputs 1-50]</a> ';    
echo '<a href=supp.php?input_set=flickr2&flag_select=1&page=2>[Show inputs 51-'.htmlspecialchars(sizeof($images)).']</a></h1>';
echo '<h2> *** If the webpage stops loading, please release the cache by refreshing. Mac: command+shift+R, Win: ctrl+shift+R.</h2>';

echo '<hr>';

$hard_matting=array('138893881_71f74f3e35_o', '3098125602_3d9c75402a_o', '4376153706_c148a92882_o');
$blur=array('6342430723_c8e126f2f3_o','6343764775_57d46c711a_o','6146621199_393b622aa2_o'); 

foreach(range($start_num, $end_num) as $counter) {
  $image=$images[$counter];
  $fname=basename($image, '.jpg');
  echo '<a href=#'.htmlspecialchars($counter).'><img src="results/transfer_crop/'.htmlspecialchars($input_set).'/'.htmlspecialchars($fname).'.jpg" height=90 border=1/></a>';
}
echo '<br><h3>*Click the thumbnail to directly go to the result.</h3>';

echo '<hr>';

#
#      <br>The examples in the same colum are from the same photographer (all unfiliated with the project). 
#      <br>From the first to the third colum, the photographers are 
#      <a href=http://www.kelco.us/exteriors/>Kelly Castro</a>, 
#      <a href=http://www.vh-artists.com/index.html#/photographers/martin-schoeller/portfolios/close-up-2/0>Martin Schoeller</a>,
#      and <a href=http://www.platonphoto.com/portraits/politics/index.html>Platon</a>. 
#      <br> Click the above external links to enjoy part of their portraits and styles online. 

# Display input/results
foreach(range($start_num, $end_num) as $counter) {
  $image=$images[$counter];
  $fname=basename($image, '.jpg');
  echo '<a id="'.htmlspecialchars($counter).'">';
  echo '<h2><li>Test id='.(htmlspecialchars($counter+1)).', file name='.htmlspecialchars($fname).'</h2></li>';


  $input_note='';
  if (in_array($fname, $eye_highlight)){
    $input_note='(E*)';}
  if (in_array($fname, $alpha_mask)){
    $input_note=$input_note.'(A*)';}

  echo '<figure style="display:inline-block; text-align:center">
    <img src="../release/clip/clipped/'.htmlspecialchars($input_set).'/'.htmlspecialchars($fname).'.jpg" width=500  border=1 style="border-color: #ffffff"/>
    <figcaption><h2>Input image '.htmlspecialchars($input_note).'</h2></figcaption>
  </figure>';

  foreach ($styles as $style){
    $id=1;
    $cmap_note='';
    if($flag_select){
      if($style=="martin"){
        $id=$martin_choice[$fname];
      }elseif($style=='kelco'){
        $id=$kelco_choice[$fname];
      }elseif($style=='platon'){
        $id=$platon_choice[$fname];
        if (in_array($fname, $cmap_platon))
          {$cmap_note='(C*)';}
    }}

    echo '<div style="position: relative; left: 0; top: 0; display:inline-block; padding: 0px">
      <figure style="text-align: center">
      <img src="../release/clip/clipped/'.htmlspecialchars($input_set).'_'.htmlspecialchars($style).'/'.htmlspecialchars($fname).'_'.htmlspecialchars($id).'.jpg" width=500/ 
          border=1 style="border-color: #ffffff">
          <img src="results/examples/'.htmlspecialchars($input_set).'_'.htmlspecialchars($style).'/'.htmlspecialchars($fname).'_'.htmlspecialchars($id).'.jpg"  
               border=1 width=120 style="position: absolute; bottom:0px; right:0px;"/>
      <figcaption><h2>Style: '.htmlspecialchars($style).' ('.htmlspecialchars($id).')'.htmlspecialchars($cmap_note).'</h2></figcaption>
      <figure/>
          </div>';
  }
  /*
  if (in_array($fname, $eye_highlight)){
    $style='martin';
    echo '<div style="position: relative; left: 0; top: 0; display:inline-block; padding: 0px">
      <figure style="text-align: center">
      <img src="results/transfer_crop/'.$input_set.'_'.$style.'/'.$fname.'_'.$id.'_fixed.jpg" width=400/ 
          border=1 style="border-color: #ffffff">
          <img src="results/examples/'.$input_set.'_'.$style.'/'.$fname.'_'.$id.'.jpg"  
               border=1 width=120 style="position: absolute; bottom:0px; right:0px;"/>
      <figcaption style="text-align:left;"><h3>Fixed the eye higlight by hand</h3></figcaption>
      <figure/>
          </div>';}

  if (in_array($fname, $alpha_mask)){
    $style='martin';
    $id=$martin_choice[$fname];
    echo '<div style="position: relative; left: 0; top: 0; display:inline-block; padding: 0px">
      <figure style="text-align: center">
      <img src="results/transfer_crop/'.$input_set.'_'.$style.'/'.$fname.'_'.$id.'_fixed.jpg" width=400/ 
          border=1 style="border-color: #ffffff">
          <img src="results/examples/'.$input_set.'_'.$style.'/'.$fname.'_'.$id.'.jpg"  
               border=1 width=120 style="position: absolute; bottom:0px; right:0px;"/>
      <figcaption style="text-align:left;"><h3>Fixed the alpha mask by hand</h3></figcaption>
      <figure/>
          </div>';}
   if (in_array($fname, $cmap_platon)){
    $style='platon';
    $id=$platon_choice[$fname];
    echo '<div style="position: relative; left: 0; top: 0; display:inline-block; padding: 0px">
      <figure style="text-align: center">
      <img src="results/transfer_crop/'.$input_set.'_'.$style.'/'.$fname.'_'.$id.'_fixed.jpg" width=400/ 
          border=1 style="border-color: #ffffff">
          <img src="cmap/'.$input_set.'/'.$fname.'.png"  
               border=1 width=120 style="position: absolute; bottom:0px; right:0px;"/>
      <figcaption style="text-align:left;"><h3>Fixed the hair by the constraint map <br> in bottom right</h3></figcaption>
      <figure/>
          </div>';}


    if (in_array($fname, $hard_matting))
      echo'<br>* Alpha mask is very challenging in this input.';
    if ($fname=='7093390373_e66faba346_o')
      echo '<br> * This input contains a lot of image noise';
    if ($fname=='105415829_63735f2374_o')
      echo '<br> * We did not correct the red eye effect';
    if ($fname=='4057711393_cf0cb75243_o')
      echo '<br> * Our color style data-base is lack of old man with big beard, so we cannot find a good match.';
    if ($fname=='4489008658_f9d8cab630_o')
      echo '<br> * For color style, our matching algorithm fails in finding good candidates';
    if ($fname=='4583418416_290d7e40a4_o')
      echo '<br> * Alpha mask missed some parts of the hair.';
    if ($fname=='5375187885_332a98e7b2_o')
      echo '<br> * The input is taken under harsh lighting';
    if (in_array($fname, $blur))
      echo '<br> * The input is blurry';
    if ($fname=='6273386092_e3a39fe19a_o')
      echo '<br> * Our color-style data-base is lack of man with white hair';
    if ($fname=='8519469936_afafb426c7_o')
      echo '<br> * The input contains hard shadow caused by the glasses. Our method cannot remove it';
   */
 


 

  

  echo '<br/><hr>';
}

echo '<div id="footnote">';
if ($page==1){
  echo '<h1><a href=supp.php?input_set=flickr2&flag_select=1&page=2>Show next 51-'.htmlspecialchars(sizeof($images)).' results</a></h1>'; 
}elseif($page==2){
  echo '<h1><a href=supp.php?input_set=flickr2&flag_select=1&page=1>Show previous 1-50 results </a></h1>';} 

echo '</div>';


echo '</div>';
echo '</html>';
?>
