title: open .raw image data using python
body: <p>I have been searching google for the method to display a raw image data using python libraries but couldn't find any proper solution. The data is taken from a camera module and it has the '.raw' extension. Also when I tried to open it in the terminal via 'more filename.raw', the console said that this is a binary file. Vendor told me that the camera outputs 16-bits raw greyscale data. </p>
  
  <p>But I wonder how I can display this data via PIL, Pillow or just Numpy. I have tested the PIL's Image module. However, it couldn't identify the image data file. It seems the PIL doesn't consider the .raw file as an image data format. BMP files could be displayed, but this '.raw' couldn't.</p>
  
  <p>Also when I tried with just read function and matplotlib, like the followings</p>
  
  <pre><code>from matplotlib import pyplot as plt
  f = open("filename.raw", "rb").read() 
  plt.imshow(f) 
  plt.show()
  </code></pre>
  
  <p>then an error occurs with </p>
  
  <blockquote>
    <p>ERROR: Image data can not convert to float</p>
  </blockquote>
  
  <p>Any idea will be appreciated.   </p>
  
  <p>link:
  <a href="https://www.leopardimaging.com/LI-USB30-M021.html" rel="noreferrer">camera module</a></p>
  
  <p>I made some improvement with the following codes. But now the issue is that this code displays only some portion of the entire image.</p>
  
  <pre><code>from matplotlib import pyplot as plt
  import numpy as np
  from StringIO import StringIO
  from PIL import *
  scene_infile = open('G0_E3.raw','rb')
  scene_image_array = np.fromfile(scene_infile,dtype=np.uint8,count=1280*720)
  scene_image = Image.frombuffer("I",[1280,720],
                                   scene_image_array.astype('I'),
                                   'raw','I',0,1)
  plt.imshow(scene_image)
  plt.show()
  </code></pre>