title: How do I generate a trimap from a binary mask?
body: <p>I'm trying to implement this paper right now:</p>
  
  <p><a href="https://users.soe.ucsc.edu/~siqin/papers/ICME.pdf" rel="nofollow noreferrer">Automatic Skin and Hair Masking Using Convolutional Neural Networks</a></p>
  
  <p>I've gotten the FCN and CRF part working, and I found the code to generate the alpha mask once I have the trimap.</p>
  
  <p><a href="https://i.stack.imgur.com/YfwG5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YfwG5.png" alt="Diagram from Paper"></a></p>
  
  <p>I'm stuck on the part between (c) and (d), though. </p>
  
  <p>How do I generate a trimap given the binary mask? The paper says:</p>
  
  <blockquote>
    <p>We apply morphological operators on the binary segmentation
    mask for hair and skin, obtaining a trimap that indicates
    foreground (hair/skin), background and unknown pixels. In
    order to deal with segmentation inaccuracies, and to best capture
    the appearance variance of both foreground and background,
    we first erode the binary mask with a small kernel,
    then extract the skeleton pixels as part of foreground constrain
    pixels. We also erode the binary mask with a larger kernel to
    get more foreground constrain pixels. The final foreground
    constrain pixels is the union of the two parts. If we only keep
    the second part then some thin hair regions will be gone after
    erosion with a large kernel. If a pixel is outside the dilated
    mask then we take it as background constrain pixel. All other
    pixels as marked as unknown, see figure 2 (d).</p>
  </blockquote>