title: How to convert raw images into png using python
body: <p>I'm trying to convert raw image data into png with python.
  I'm pretty new to python and especially to image processing...</p>
  
  <p>The raw file is a 16 bit greyscale image.</p>
  
  <p>As I already scanned the forums I came up with the following solution:</p>
  
  <pre><code>from PIL import Image, ImageFilter
  import numpy as np
  from scipy import ndimage, misc
  
  
  rawfile = np.fromfile('test.raw', dtype=np.int16)
  
  rawfile.shape = (1025,1025)
  imgSize = (1025,1025)
  
  img = Image.fromstring('L', imgSize, rawfile, 'raw', 'F;16')
  img.save("rawData.png")
  </code></pre>
  
  <p>But I keep getting the following errors:</p>
  
  <pre><code>Traceback (most recent call last):
    File "****\Programs\Python 2.7.6\readraw\readraw.py", line 11, in &lt;module&gt;
      img = Image.fromstring('L', imgSize, rawfile, 'raw', 'F;16')
    File "****\Programs\Python 2.7.6\lib\site-packages\PIL\Image.py", line 1835, in fromstring
      return frombytes(*args, **kw)
    File "****\Programs\Python 2.7.6\lib\site-packages\PIL\Image.py", line 1822, in frombytes
      im.frombytes(data, decoder_name, args)
    File "****\Programs\Python 2.7.6\lib\site-packages\PIL\Image.py", line 608, in frombytes
      d = _getdecoder(self.mode, decoder_name, args)
    File "****\Programs\Python 2.7.6\lib\site-packages\PIL\Image.py", line 390, in _getdecoder
      return decoder(mode, *args + extra)
  ValueError: unknown raw mode
  </code></pre>
  
  <p>Can someone explain to me why the raw mode is unknown? I checked the Docs and as far as I understand the topic, the PILLOW lib should come with this?!</p>
  
  <p>Best regards</p>
  
  <hr>
  
  <p>Thank you guys for your help!</p>
  
  <p>I altered my code and now it seems to work:</p>
  
  <pre><code>from PIL import Image, ImageFilter
  import numpy as np
  from scipy import ndimage, misc
  
  
  rawfile = np.fromfile('test.raw', "uint16")
  
  rawfile.shape = (1025,1025)
  misc.imsave("test.png", rawfile)
  </code></pre>