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 6 6]
   [0 1 1 0 0 0 0 0 0 7 0 0 0 3 3 0 0 0 4 4 0 0 0 0 5 5 5 5 5 0 2 2 0 2 2 2 0 0 0 2 2 2 0 6 6 0 0 0 6 6 0 0 6 6]]
  </code></pre>
  
  <p>As a first step I want the pixels different than 0 to be white and the 0 pixels to be black.what i did to transform the none 0 values all to 1:</p>
  
  <pre><code>binary_transform = np.array(labels).astype(bool).astype(int)
  </code></pre>
  
  <p>and it worked then i want to transform the list of arrays of 1s and 0s to image, what i tried:</p>
  
  <pre><code>from PIL import Image
  
  img = Image.fromarray(binary_transform, '1')
  img.save('image.png')
  </code></pre>
  
  <p>the docs for <code>Image.fromarray</code> can be found here <a href="https://pillow.readthedocs.io/en/3.1.x/reference/Image.html" rel="nofollow noreferrer">https://pillow.readthedocs.io/en/3.1.x/reference/Image.html</a></p>
  
  <p>It didn't work then i tried the following:</p>
  
  <pre><code>import png
  
  png.from_array(binary_transform, 'L').save('image.png')
  </code></pre>
  
  <p>Referring to the docs <code>'L'</code> is for grayscale while i want binary but i didn't see a binary option, the docs <a href="https://pythonhosted.org/pypng/png.html" rel="nofollow noreferrer">https://pythonhosted.org/pypng/png.html</a></p>
  
  <p>and i got this error  <code>ValueError: bitdepth (64) must be a positive integer &lt;= 16</code></p>