function bw2 = thin (bw)
  
  lut1 = makelut (@thin_fun1, 3);
  lut2 = makelut (@thin_fun2, 3);
  
  fp = fopen ('lut1.txt', 'wt');
  fprintf (fp, '        lut1 = logical ([');
  for i=1:16
    for j=1:32
      fprintf (fp, '%d;', lut1((i-1)*32+j));
    end
    if (i != 16)
      fprintf (fp, '\n                         ');
    else
      fprintf (fp, ']);\n');
    end
  end
  
  fclose (fp);
  
  fp = fopen ('lut2.txt', 'wt');
  fprintf (fp, '        lut1 = logical ([');
  for i=1:16
    for j=1:32
      fprintf (fp, '%d;', lut2((i-1)*32+j));
    end
    if (i != 16)
      fprintf (fp, '\n                         ');
    else
      fprintf (fp, ']);\n');
    end
  end
  
  fclose (fp);

  bw1 = applylut (bw, lut1);
  bw2 = applylut (bw1, lut2);
  end
